gmynd v1.0.5
G•M•Y•N•D
A javascript utility library
This library serves for (students) data visualization projects. It provides some data manipulation functions and other utility functions to make the life of javascript programming a bit easier. It's just a set of convenience functions, not a framework.
Some remarks about naming functions and arguments
In this context "data" always refers to a JSON representation of a table, which is an array of simple objects like:
let superheroes = [
{Name:"A-Bomb", Height:203, Weight:441},
{Name:"Abe Sapien", Height:191, Weight:65},
{Name:"Abin Sur", Height:185, Weight:90},
{Name:"Abomination", Height:203, Weight:441},
{Name:"Absorbing Man", Height:193, Weight:122},
...
]This kind of JSON is usually generated if you convert a CSV-file to JSON. The original CSV of the example above would look like this:
Name,Height,Weight
A-Bomb,203,441
Abe Sapien,191,65
Abin Sur,185,90
Abomination,203,441
Absorbing Man,193,122
...We will refer to the column titles (e.g. Name, Height, Weight) as properties or props and to the rows as data objects or entries.
Installation
Either copy ./src/gmynd.js to your project folder or install it in any node.js project:
npm install gmyndLoad the functions into your node script:
const gmynd = require("gmynd");Reference
Data manipulation
sortData(data, props)groupData(data, props)->objectcumulateData(data, props, [calculations])->newDatamergeData(data1, data2, prop1, [prop2])->newDataintersectData(baseData, filterData, prop1, [prop2])->newDatafindAllByValue(data, prop, val)->newDatafindFirstByValue(data, prop, val)->objectdeleteIncompleteData(data, props, [emptyValues])->newDatadeleteDuplicateData(data, prop, [keepFirst])->newDatafilterPropType(data, prop, allowedType)->newDataconvertPropToNumber(data, prop, [nullNaNs])->newDataconvertPropToBoolean(data, prop, [strictMode])->newDataaddPropPercentage(data, prop, [propName])->newDataaddPropSegment(data, prop, segmentCount, [start], [end], [propName])->newDataaddPropRank(data, prop, [propName])->newDataarrayFromProps(obj, props, [fallbackVal])->arrayarrayFromPropsInData(arr, props, propName, [deleteProps], [fallbackVal])->newDatarenameProps(data, props, names)->newData(orobj->newObj)deleteProps(data, props)->newData(orobj->newObj)dataMin(data, prop)->numberdataMax(data, prop)->numberdataExtremes(data, prop)->objectdataSum(data, prop)->numbersaveData(data, [filename], [pretty])
Array helpers
arraySum(arr)->numberarrayCount(arr, val)->numberarrayAverage(arr, [ignoreEmpty])->numberarrayLast(arr, [ignoreEmpty])->someValueshuffleArray(arr)->array
Math and utilities
map(value, low1, high1, low2, high2, [clipping])->numberlerp(value1, value2, t)->numberclip(value, min, max)->numberrandom(low, high)->numberrandomInt(low, high)->numberradians(degree)->numberdegrees(radians)->numberdistance(x1, y1, x2, y2)->numbercartesian(radius, angle)->objectpolar(x, y)->objectcircleRadius(area)->numbercircleArea(radius)->numberrange(start, stop, [step])->arrayduration(date1, date2)->numberweekOfYear(date, [returnYear])->numberorarraydayOfYear(date)->numberisString(value)->booleanisArray(value)->booleanisObject(value)->booleanversion()->string
Acknowledgements
Example data from
https://www.kaggle.com/dannielr/marvel-superheroes
https://ourworldindata.org/age-structure
https://ourworldindata.org/gender-ratio
Suggestions? Bugs? File an issue! :)