Giter VIP home page Giter VIP logo

editor-backend's Introduction

Vega: A Visualization Grammar

Vega Examples

Vega is a visualization grammar, a declarative format for creating, saving, and sharing interactive visualization designs. With Vega you can describe data visualizations in a JSON format, and generate interactive views using either HTML5 Canvas or SVG.

For documentation, tutorials, and examples, see the Vega website. For a description of changes between Vega 2 and later versions, please refer to the Vega Porting Guide.

Build Instructions

For a basic setup allowing you to build Vega and run examples:

  • Clone https://github.com/vega/vega.
  • Run yarn to install dependencies for all packages. If you don't have yarn installed, see https://yarnpkg.com/en/docs/install. We use Yarn workspaces to manage multiple packages within this monorepo.
  • Once installation is complete, run yarn test to run test cases, or run yarn build to build output files for all packages.
  • After running either yarn test or yarn build, run yarn serve to launch a local web server โ€” your default browser will open and you can browse to the "test" folder to view test specifications.

This repository includes the Vega website and documentation in the docs folder. To launch the website locally, first run bundle install in the docs folder to install the necessary Jekyll libraries. Afterwards, use yarn docs to build the documentation and launch a local webserver. After launching, you can open http://127.0.0.1:4000/vega/ to see the website.

Internet Explorer Support

For backwards compatibility, Vega includes a babel-ified IE-compatible version of the code in the packages/vega/build-es5 directory. Older browser would also require several polyfill libraries:

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.4/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/runtime.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fetch.umd.min.js"></script>

Contributions, Development, and Support

Interested in contributing to Vega? Please see our contribution and development guidelines, subject to our code of conduct.

Looking for support, or interested in sharing examples and tips? Post to the Vega discussion forum or join the Vega slack organization! We also have examples available as Observable notebooks.

If you're curious about system performance, see some in-browser benchmarks. Read about future plans in our roadmap.

editor-backend's People

Contributors

algomaster99 avatar ashu8912 avatar dependabot-preview[bot] avatar dependabot[bot] avatar domoritz avatar p42-ai[bot] avatar risinggeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

editor-backend's Issues

Sign in does not work on Safari

Somehow, I cannot sign in on safari. After going through the login process on github, I don't get signed in on the editor.

Implementation of pagination

Overview

Pagination in GraphQL isn't done using page numbers like in a standard API endpoint which looks something like this: https://example.com/?page=1. In graphQL, we use cursor which a base64 encoded string or offset (this method is not available in octokit/grapql). Please read about these methods here - https://graphql.org/learn/pagination/#pagination-and-edges.
Therefore, we might need to resort to store cursors on front-end to paginate.

Working

I will first explain what queries and its corresponding outputs mean.

Input Query

{
  user(login: "algomaster99") {
    gists(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) {
      edges {
        cursor
        node {
          name
          description
        }
      }
      pageInfo {
        startCursor
        hasPreviousPage
        endCursor
        hasNextPage
      }
      totalCount
    }
  }
}

Output

{
  "data": {
    "user": {
      "gists": {
        "edges": [
          {
            "cursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0zMFQwMToyNjo0NSswNTozMM4F17K9",
            "node": {
              "name": "19adeb7cfaffadeefda5b39a412f317c",
              "description": "Latest"
            }
          }
        ],
        "pageInfo": {
          "startCursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0zMFQwMToyNjo0NSswNTozMM4F17K9",
          "hasPreviousPage": false,
          "endCursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0zMFQwMToyNjo0NSswNTozMM4F17K9",
          "hasNextPage": true
        },
        "totalCount": 4
      }
    }
  }
}

Explanation of output

  • Edges: It is an array of all the gists fetched according to the condition (first: 1, orderBy: {field: CREATED_AT, direction: DESC}). Fetching of one gist is enforced by: first: 1

    • Cursor: This is a base64 encoded string which is, I think, a unique way to index gists.
    • Node: This is a gist object. The name and description attributes correspond to the ID and title of the gists.
  • PageInfo: This gives the details about the pages.

    • Start cursor: Shows the cursor of the first gist.
    • End cursor: Shows the cursor of the last gist.
    • hasPreviousPage: Checks if there are any gist before the startCursor.
    • hasNextPage: Checks if there are any gists after the endCursor.

All gists corresponding to cursors between startCursor and endCursor are displayed in edges.

  • Total count: Shows the number of gists.

Solution

To implement pagination, let us consider the following assumptions first:

  • Number of gist in one page: 2 (I am taking my case specifically ๐Ÿ˜…)
  1. When we open the Gist modal on front-end, an initial request will be made to the back-end to get the following data:-
  • Total edges as an array of cursors.
  • First page data (the details of first two gists).
"edges": [
          {
            "cursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0zMFQwMToyNjo0NSswNTozMM4F17K9",
            "node": {
              "name": "19adeb7cfaffadeefda5b39a412f317c",
              "description": "Latest",
              "files": [
                {
                  "name": "spec.json"
                }
              ]
            }
          },
          {
            "cursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0yOFQxMjowNjoyOSswNTozMM4F1z-E",
            "node": {
              "name": "e5cf1cc1e12a40bc0a69cf77c934f239",
              "description": "It works so fine!",
              "files": [
                {
                  "name": "test.vl.json"
                }
              ]
            }
          },
          {
            "cursor": "Y3Vyc29yOnYyOpK5MjAxOS0wOC0yM1QwNzo1Mjo1OCswNTozMM4F1g8C",
            "node": {
              "name": "6ee25328dd6aa5c86476b0fa5d4a85b9",
              "description": "Google Summer of Code 2019 - Final Evaluation",
              "files": [
                {
                  "name": "GSOC19.md"
                }
              ]
            }
          },
          {
            "cursor": "Y3Vyc29yOnYyOpK5MjAxOC0xMi0xNVQyMTowNToxOSswNTozMM4FlBQJ",
            "node": {
              "name": "830edacfc6b36fcf5604332cf7b8cbc1",
              "description": "Key generation using RSA algorithm",
              "files": [
                {
                  "name": "key_generation.py"
                }
              ]
            }
          }
        ],
"totalCount": 4
  • An array of all cursors will be sent.
  • The ID, files, etc. of first two gists will be sent to display the information for the first page.
  1. Since there are 4 gists in total, the pagination component will look like this:
    | โฌ…๏ธ | 1 (selected) | 2 | โžก๏ธ |

  2. Clicking on 2 will find the corresponding cursor from the array and send a request to back-end. For example, assume the array is as follows: ['1', '2', '3', '4']. Since we have two gist on the first page, the second page will have the following two gist viz 3 and 4. So the nextCursor will be 3.

The query can look like this:

{
  user(login: "algomaster99") {
    gists(first: 2, after: "2" orderBy: {field: CREATED_AT, direction: DESC})
...

This will get 3 and 4.

One problem

The above solution works well for people who have 100 gist. first attribute in the query allows to fetch only 100 gists at a time. Therefore, we will have cursors for all 100 gists.

Question Why getting all cursors are important?
If someone from 1st page goes to 103rd page (suppose), we will need the 206th cursor to get contents of that page.

Can't run in dev mode

# yarn start                                                                                   yarn run v1.22.0
$ now dev
Now CLI 17.0.3 dev (beta) โ€” https://zeit.co/feedback
Error! The following env vars are not defined in `.env` file:
  - "GITHUB_CLIENT_ID"
  - "GITHUB_CLIENT_SECRET"
  - "REDIS_HOST"
  - "REDIS_PASSWORD"
  - "REDIS_PORT"
  - "SESSION_SECRET"
Read more: https://err.sh/now/missing-env-file
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Make backend stateless

We could probably just pass the auth token to the editor frontend and make the backend stateless. This would mean that we could do the graphql queries from the frontend directly.

Choice of database

We can search over the following things for vega and vega-lite visualization:-

  • Description of the visualization it can be of the visualization or the gist.
  • Type of graph
  • Search a specific user's visualization

Elasticsearch DB

  • This DB doesn't support relations between any fields. One wouldn't be able to link user and its gist. This will be a problem when we are searching for visualization according to a user.
  • It also doesn't have an updated ODM. Making search queries will be difficulty and be a little long. Current version of elasticsearch is 7.0.0 while its ODM was updated a year ago for 5.0.0.
  • This repository's file simply makes api calls to GitHub's api to retrieve a user and the clicked GistID.
  • Searching can be performed like they have done in this file. The queries written in there are quite long to write. Also, it is good for textual search over random data. It can't search for visualization according to users. Our data is very organized and can be simply put in a schema.
  • ElasticSearch does not provide any authentication or access control functionality.
  • I think it would have been a good choice if had to just search over random texts.

PostgreSQL vs. MongoDB

  • They both are pretty good with MongoDB having a famous ODM called Mongoose.
  • I am inclined towards MongoDB since it deals with JSON objects which need not be serialized before rendering it in an API view. Hence, shortening the process.
  • Since our schema definition isn't really perfect for gists because we don't know yet what users would search over, MongoDB is a better choice since it stores document like data and doesn't necessarily require a predefined structure. So later on we can add more fields in a gist so that it can be easily indexed and searched over.

Add favicon

We can add favicon using this link but Express has different instructions to set it up. It suggests to install serve-favicon and have the favicon.ico file as a static file in the repository. Should we download it and keep at as an asset in the project?

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.