sigma.js: can't display graph with json - javascript

I have difficulty display graph with json file. I have try to run the example(load-external-json.html) provide by the application but it can't display graph.
I look through the web for solution but haven't find one solution that solve my problem.
the plug-in use: plugins/sigma.parsers.json/sigma.parsers.json.js
sigma.parsers.json("data/arctic.json", // Here I need to put the filepath instead of "data.json"
{
container: document.getElementById('container'),
settings: {
defaultNodeColor: '#00a',
edgeColor: 'default',
defaultEdgeColor: '#a00'
} });
Best Regards,
luis

I believe this plugin makes an XHR request to get the specified file (in this case data/arctic.json). That means you may need a run a server locally in order to see this work properly.
If you have Python installed, an easy way to do this is to run python -m SimpleHTTPServer from the directory where load-external-json.html is located. Then you should be able to see it live at http://localhost:8000/load-external-json.html.

From sigma.js wiki on github:
Sigma provides many code examples to show you what it can do and how to use it. Some of these examples load external data files, and you need to access them through a local server to see the examples working.
you need to run a simple Node based http server. Just follow the instructions on the wiki:
https://github.com/jacomyal/sigma.js/wiki

Related

How to programatically create pull request with changed file using GitHub API

How can I create PR on Github using their API? Let's imagine I have package.json file as a string and I want to make changes to this file. So I parse it, make changes to it and then what exactly I need to do to make it look like I made those changes locally after checking out the new branch, making changes, commiting them to new branch and the pushing them to remote? I see that they have POST API endpoint to create a commit and POST API endpoint to create a PR, but I don't see where I put the file I changed.
Using something like GitJS could be a solution.
This library is a simple wrapper around the git command line.
Instead of using the Github API you could just work the git commands programatically with a library like this.
That way you don't have to work with the much more complicated API and have the benefit of supporting other source control sites too.
Looking at their example we can see it's incredibly easy to commit and push a file using javascript:
require('simple-git')()
.add('./*')
.commit("first commit!")
.addRemote('origin', 'some-repo-url')
.push(['-u', 'origin', 'master'], () => console.log('done'));
Make sure you refer to the usage documentation before trying that example to ensure you configure everything correctly.
Alternatively, you can use the package Octokit to more easily interface with the Github API.
When adding, committing and pushing a file via the API you must first start by creating a tree. Then you use that tree as part of the commit request, update the references and finally push the commit.
You can find a working example on this Github issue.

Compiling Latex with Javascript

I am working on a webapp(written with react-js) that generates a Latex code which contains information to give to the user. My goal is to let the user download the PDF file directly from my application.
I first tried using this library: texlive.js, that seemed to work but really it's impossible to recompile(their "Makefile" is not meant to handle new packages) if you try to add new packages(only some basic ones work).
So I thought about using the overleaf APIs but they don't let you obtain the pdf without sending the user to their website.
Any advice to make one of them work or any other way to achieve my goal?
You can install your package in texlive.js without using MakeFile
Sorry I am not expert in answering but here is how i made it work
I wanted to implement exam paper generation using javascript
Required Package/Class : exam
I created "\texlive.js\texlive\texmf-dist\tex\latex\exam\exam.cls"
Added this to
"\texlive.js\texlive\texmf-dist\ls-R"
./tex/latex/exam:
exam.cls
And Then \texlive.js\texlive.lst
/texmf-dist/tex/latex/exam/.
And
/texmf-dist/tex/latex/exam/exam.cls
I've recently found this project:
https://github.com/SwiftLaTeX/SwiftLaTeX
I've tested it with a few documents and it seems to work. It downloads the needed packages from the web, see available packages: https://www.ctan.org/. I haven't gone deeper into passing images to the engine but it should be possible. See the official demo: https://www.swiftlatex.com/#demo
Here is the official guide with the download link for the already compiled wasm files and with the js bindings: https://www.swiftlatex.com/#install

Make a small HTML application update a JSON file

I want to make a local HTML application read and update a JSON file and use its content to display HTML content. Alas, I'm stuck at the very first step, as I can't seem to setup any sort of test file that simply notices and reads a JSON file. From what I see online, I need to use other libraries. I attempted to use require.js but I can't make it work and the documentation doesn't help me.
I imported the require.js with a tag and attempt to launch something out of what I got from the documentation, but there's nothing to do. It doesn't look like it's willing to take .json files.
requirejs([
'example'
], function(example) {
const config = require('./config.json')
});
My issue is to get the program to read the file. From there I believe I can make the display of it, but this JS thing is all alien to me.
The recommended way would be to run a web server or use something like Electron and build a desktop app (as #chrisG points out in the comments). But if you wanna do this in the browser without an web server you could do something like:
Run Chrome with the --allow-file-access-from-files (or however you allow local file access in your browser of choice)
Put your JSON in a js file and load it (to just do this you don't need the flag, but if you want to use absolute path you'll need it)

Call Python script from local JavaScript App

so I've looked around quite a bit now and wasn't able to find quite the use case I think I am confronted with.
For some background:
I'm fairly new to JavaScript and have never had to call any other program/script from it. Now I did develop a Python script that pulls some data from online sources, formats it and dumps it into JSON files. In order to display this data in a proper way I figured I would use Electron.
While handling the JSON files is completely fine (would be quite sad if it wasn't I guess), I need to be able to call the Python script updating the data from my Electron UI. As everything is local, I hoped, that there would be an easier way, than setting up some server for the Python script to run on, just to be able to trigger its execution from my Desktop App. This is especially true, as I don't even need to get or process any returns, I just want to trigger the execution of that script.
So the question now is: is there such an "easy" way to execute Python scripts from an Electron/JavaScript based locally saved Desktop app?
Thanks in advance for any answers!
Like a previous commenter mentioned, you should be able to follow this SO answer in Node.js (which is what Electron uses).
To expound upon that answer just a bit, I'd recommend using the built-in Python JSON utility to dump JSON to the standard out (just printing out the JSON string), and the using the built-in Node.js JSON utility to parse that JSON string into a javascript object for use in your application.
Alright, so after being redirected to this thread, which I can only recommend reading through if you have an interest in this issue, I took their solution and altered a little, which took me a bit of time, due to some confusion, which I now would like to spare you guys!
To re-introduce the issue: The goal is to call a python script from a JavaScipt/Electron based UI. The python script only needs to be executed, but it needs to happen onClick, as it is an update function.
Now this is the code I used:
const exec = require("child_process").exec;
function triggerUpdateAndRefreshFooter() {
exec('python relativePathToScript/update.py',
function(error, stdout, stderr) { //callback function, receives script output
refreshFooter(); //don't use the output, but I could here
}
)
}
I did have some issues figuring out all of that const stuff in the other thread, as well as having to guess IF I could just execute my script in a separate function. In the end this did work!
I hope this was helpful!

How to load file contents from another domain using just JS?

I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.
Is this possible? If so any hints or examples would be appreciated.
Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.
The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.
The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.
Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.
(will expand the answer later).
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22
One of the limitations of this method is file size, it currently tops out at 25k.

Categories