Skip to content

JS code for the shared constellation module used on Membean and Memseed.

Notifications You must be signed in to change notification settings

membean/wordmap

Repository files navigation

Wordmap Demo

Wordmap

The Wordmap is a tool that enhances vocabulary learning through visual organization, and is a shared module that can be utilized on both Membean and Memseed.

Install the package using yarn.

yarn add 'wordmap@https://github.com/membean/wordmap.git#v0.0.8'

Install the package using npm

npm install 'wordmap@https://github.com/membean/wordmap.git#v0.0.8'

Note: you must have access to Wordmap repository in order to install it as node package / module.

Usage of WordMap

Using React

  1. Create container element
import React, {useRef}  from 'react';
...
...
function App() {
  const containerRef = useRef();
  ...
  ...
  ...
  
  return (
    <>
      <div className="container" ref={containerRef}></div>
    </>
  )
  
  ...
}


  1. Import the Wordmap Module.

import Wordmap from 'wordmap';

  1. Call the Wordmap constructor with input containerElement & json data url.
...
...
  useEffect(() => {
    new WordMap(
      {
        containerEle: containerRef.current,
        url: WORD_URL // url to be set from env.
      }
    )

    return () => {
      containerRef.current.removeChild(containerRef.current.children[ 0 ])
    }
  }, [])
  
...
...
  1. Style the container with equal width and height so the constellation graph render correctly.
.container {
  width: 350px;
  height: 350px;
  background: #2a383d;
  padding: 20px;
}
  1. React working example

Using wordmap with vanilla js

  1. Import the wordmap/bundle.js in index.html
//index.html
<script src="wordmap/bundle.js" type="module"/>

OR

//index.html
<script src="./node_modules/wordmap/bundle.js" type="module"/>

  1. Create container element
///index.html

<body>
..
..

<div class="container"></div>

</body>

  1. Create js script to call Wordmap constructor and load in index.html.
// app.js

window.addEventListener('load', () => {
  const containerRef = document.querySelector(".container");
  
  new window.Wordmap({
    containerEl: containerRef,
    url: WORD_URL // to be loaded from env or the url to wordmap.
  })
  
})

// index.html

<body>
...
...
<script src="./app.js" />
</body>

  1. Style the container with equal width and height so the constellation graph render correctly.
.container {
  width: 350px;
  height: 350px;
}
  1. React working example

Configuration

The configuration is used to change how the Wordmap behaves. There are properties to load the word map in Interactive and NonInteractive mode.

Readonly Mode

  1. configure wordmap to render constellation with word at center, just static constellation no drilldown to another word. means click on label will be disable.
new Wordmap({
  containerEle: ele,
  mode: 'word',
  url: 'url-to-constellation-json-data'
})

Readonly Mode Question page

  1. configure wordmap to render constellation with ? at center, static constellation with no interaction mostly use in questions page.
new Wordmap({
  containerEle: ele,
  mode: 'question',
  url: 'url-to-constellation-json-data'
})

Interactive Mode

  1. configure wordmap to render constellation with word at center and to make wordmap more interactive. You have to write logic to maintain the state to enable the forward and backword mode.

mostly use in word page.

new Wordmap({
  containerEle: ele,
  mode: 'question',
  data: jsonData, 
  fetchCallback: callBack // invoke when user click on labels.
})

Options & params

Property Type Type Description
containerEle Object Required A reference to the wordmap container div from the constellation component
mode string options Used to determine the constellation mode, default is 'word'
animate Boolean optional Used to turn animation on or off, default is On
url string Required / Optional Used to fetch the constellation data, [required] when constellation need to load in readonly mode like questions. [optional] when constellation needs to be interactive, eg to enable click on label
data Object Required Json data to render the constellation graph, [required] In case of interactive mode.
fetchCallBack function Required A callback fn to fetch the constellation data based on provided word, on invoke it has two params, 1. word, 2. cb to render graph with updated data [Required] in case of interactive mode.
props Object Optional Props for constellation component, default is {} e.g. fullscreen: true/false

Scripts:

To prepare the types of module just execute the below commands from root.

yarn tsc

To prepare the compiled minified version as single file so browser can easily use it.

yarn webpack

About

JS code for the shared constellation module used on Membean and Memseed.

Resources

Stars

Watchers

Forks

Packages

No packages published