npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

poem-manifests

v1.3.0

Published

Re-use visualization code by creating levels from manifests

Downloads

11

Readme

poem-manifests

Loads in a manifest that will set all of your visualization's components to a single graph object. This makes it really easy to have multiple levels or scenes and share code between them. It decouples your individual components from the logic of how your visualization loads in and works, greatly increasing the reusability of your implementation code.

Part of the programming-poem module series.

This module's concepts

manifest

An object that contains properties for your visualization, and references to the components.

graph

A central scene object that collects all of your components. It gets passed into every component.

component

A reusable bit of code like a camera, player, bad guy, background, etc. It gets passed a graph object and properties.

properties

General configuration for components. This should be stuff like the position a camera starts, how fast a bad guy moves. What image to use as a texture for a background.

Example

See the ./example folder for an example setup.

Usage

var Poem = require('./poem'); //Your graph (or central object) for your visualization
var manifests = require('./manifests'); //Your manifests object, example below

var loader = require('poem-manifests')( manifests, {
	//Configuration
	getGraph : function( manifest, slug ) {
		return new Poem();
	}
});

loader.emitter.on("load", function( e ) {
	var poem = e.graph;
	document.title = e.manifest.title;
	poem.start();
	
	//All loaded components can be accessed by the graph object
	poem.camera.followPlayer( poem.player );
});

loader.load( "intro" );

The Manifests

The typical folder structure would be something like this:

./manifests
	./index.js
	./level1.js
	./level2.js
	./level3.js

./manifests/index.js

The base manifests object should be composed of key pair values where the key is the slug of your level/scene/view that you want to load in.

module.exports = {
	level1 : require('./level1'),
	level2 : require('./level2'),
	level3 : require('./level3'),
	level4 : require('./level4')
};

./manifests/level1.js

module.exports = {
	
	// These properties do not automatically get set onto the graph object.
	// They only stay on the manifest object which gets passed to the "load" event.
	
	title : "Level 1 - My Amazing Visualization",
	menuOrder : 0,
	customConfig : {
		option1 : "value"
	},
	
	// Components are loaded onto the graph object
	
	components : {
		
		// Pseudo-code: graph.background = suppliedFunction( graph, properties );
		background : {
			function: require("../js/background"),
			properties: {
				color : 0xBADA55
			}
		},
		
		// Pseudo-code: graph.controls = new construct( graph, properties );
		controls : {
			construct: require("../js/components/cameras/Controls"),
			properties: {
				minDistance : 500,
				maxDistance : 1000,
				zoomSpeed : 0.1,
				autoRotate : true,
				autoRotateSpeed : 0.2
			}
		},
		
		// Pseudo-code: graph.controls = object;
		info : {
			object: require("../js/components/Info")
		},
		
		// Pseudo-code: graph.controls = object;
		winMessage : "You win at life."
	}
};

The loader's "load" event passes the handler the graph object (poem). This object behaves something like this given the above example:

poem.background.doSomething();
poem.controls.doSomething();
poem.info.doSomething();
console.log( poem.winMessage );

Configuration

var loader = require('poem-manifests')( manifests, {
	getGraph : function( manifest, slug ) {	return new Poem(); },
	emitter : nodeEmitter,
	globalManifest : require('./globalManifest')
});

getGraph( manifest, slug )

A function to generate the central graph object of your level. If not provided, a new blank object is used for your graph. The graph object is shared by all of your components. It typically should always create a new object.

emitter

A node.js EventEmitter. If one is set, it is used by the loop. Otherwise a new EventEmitter is created. This is useful to create a central emitter that collects common events.

globalManifest

A manifest that gets loaded for every level. Any properties on an individual level will overshadow ones on the global manifest. It's useful to declaratively configure your visualization. In pseudo-code the graph and manifests are processed like this:

_.extend( graph, globalManifest, currentManifest );

An example component

Each component gets passed the graph object and the properties. The component is called at the moment it is loaded.

function Background( graph, properties ) {
	
	this.config = _.extend({
		parallaxSpeed : 5,
		color : 0xfacade
	}, properties);
	
	this.texture = createTexture( config.color );
	
	graph.emitter.on( 'update', this.update.bind(this) );
	graph.emitter.on( 'unload', this.destroyTexture.bind(this) );
	graph.stage.add( this.texture );
	
}

Background.prototype = { ... };