Coder Social home page Coder Social logo

napchart's Introduction

Napchart

npm version

Drag-and-drop time-planning library using HTML5 and the canvas element. Used by napchart.com

enter image description here

Installation

You can download the latest version of Napchart from the GitHub releases

To install via npm:

npm install napchart --save

Create a Chart

It is easy to create a Napchart on your page. All you need is a canvas element, a resizer div and some javascript code

<div style="width:400px;height:400px">
	<canvas id="myNapchart"></canvas>
</div>
<script>
var ctx = document.getElementById("myNapchart").getContext('2d')
var myNapchart = Napchart.init(ctx, {
	// data goes here
	elements: [{
		"start":720,
		"end": 790,
		"text": "Cool text"
	},{
		"start":1420,
		"end":400
	}]
}, {
	// options go here
)
</script>

Data

The second data parameter of napchart.init defines what data should initially be drawn to the napchart. The structure is simple like this

var defaultData = {
  elements: [],
  shape: 'circle',
  lanes: 1,
  colorTags,
}

You don't need to specify shape or lanes if you don't want to. If you don't specify anything at all it will start with a blank napchart

Elements

Elements are structured like this

var element = {
  start: Number, // between 0 and 1440
  end: Number, // between 0 and 1440
  lane: Number || 0, // must not be higher or equal to chart.data.lanes
  text: String || '',
  color: Color || chart.config.defaultColor // string (red, blue...) or hex (#ffffff)
  id: Number, // automatically generated
}

Shape

String that defines which shape you want

string = 'circle' || 'wide' || 'line

Lanes

Number of how many lanes you want. Max 4 recommended

ColorTags

Array with objects that connects a color with a text string (tag). This replaces types from previous versions of napchart

colorTags = [
  { color: 'red', tag: 'Sleep'},
  ...
]

Options

The third parameter of napchart.init is an object where you can specify options. Here are the defaults

{
	interaction: true,
	penMode: true,
	background: 'transparent',
	fontColor: '#aaaaaa'
}

Contributing

See CONTRIBUTING.md for a sweet introduction to the code-base

napchart's People

Contributors

algor1th avatar christopherjenness avatar fu5ha avatar galegacy avatar gianpaj avatar kreig303 avatar lapfelix avatar larskarbo avatar thecydonian avatar thejayeye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

napchart's Issues

Option to display gap between phases (see poly examples)

This would be nice to have an option to see the lengths of time there is between the different phases.
This probably shouldn't be done by default as it might clutter the whole chart.

Alos, would it be possible to add something in the url to enable such option, when seeing the chart / generating the chart's thumbnail? This might be a feature for napchart website though.

Thanks for your awesome work!

add simple textfield to add description

I'd like to have a text field to add to my napchart to add some descriptions.
This would be helpful for weirder things like SPAMMAYL and allow to
redefine the 'work'-zones for something else (like no-coffee zones for example).

EDIT:
Also a field to enter a name. That could make conversations more precise,
when people are copying each others schedule.

Printing and PDF save

All is perfect, but needs the buttons to print to have it and to save to PDF
All the rest is good
Please do it :)

How is get elements?

Hi!

Very cool tool, thanks!

I using napchart in nuxt roject.

How can I get list of elements in code?

TypeError: Canvas.registerFont is not a function

We cannot get an image:
http://napchart.com/api/getImage?width=600&height=600&chartid=0ttrx

TypeError: Canvas.registerFont is not a function
    at module.exports (/app/server/api/getImage.js:18:10)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at /app/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at next (/app/node_modules/express/lib/router/route.js:127:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)
    at next (/app/node_modules/express/lib/router/route.js:131:14)

For the rest, http://napchart.com/app is a very nice web site / application! Thanks! :)

Image & Save URL missing "/"

When I save a created Chart I get an URL like: https://napchart.comhnb9c

  1. The "/" is missing
  2. It seems that the URLs do not work with the "https://" (on napchart.com) I think this is a problem with a missing certificate.

The same Problem occurs for the Image-URLs.
https://napchart.comapi/getImage?width=600&height=600&chartid=plypn
Without the "https://" and with the "/" everything works fine.

Add file extension to api/getImage

A number of websites are skeptical of allowing images from urls without file extensions (like discord).

Would you consider updating api/getImage to generate with a file extension?

simply changing it to api/getImage.jpg or api/getImage.png and updating your endpoints might work (haven't tried this)

Show examples in readme

Part of what makes this project so cool is the beautiful visualizations. It would be nice to showcase these in the readme so people can see what the project outputs.

Saving does not work

Example anecdote: If I set an Everyman 3 schedule with 1x core + 3x 20' and SAVE it, it stores only the core without any of the 20' naps

What is v2 branch?

What is the relationship between v2 and master branches?

What should a contributor attempt to work off of?

Colour-coding of different busy elements

When I'm building a napchart right now you have core, nap and busy. Sleeps are in red and busy periods in grey. I would really like to be a bit more detailed than this, e.g. instead of "busy" I would like to have "working" and "travelling" so I can label those separately. I would also like these to be in separate colours, maybe with the ability to choose the colour for each thing. For example, I might choose to have 'travelling' sections in green.

feature: Whole lane shift

Hi! Love your work.

It'd be really useful to shift/move an entire lane back and forth, not just individual elements in that lane.

Especially when designing a polyphasic schedule, one might first pay more attention to the rhythm of sleep blocks than their start times.
Being able to shift the entire lane to line up with other times whilst maintaining the gaps between sleep blocks would be very handy.

Get back the sample schedules

The sampleSchedules module is there, but it is not enabled.

The UI for this module should be like it was in the previous version.

Missing Dymaxion sleep schedule

Dymaxion schedule is based on 4 30-minute naps spread throughout the day. Hence, total sleep time is 2 hours and up-time is 22 hours.

Add Contribution Intro (& Guidelines) to README.md

I'd like to help but it's quite a drawback to not have a little introduction on what needs to be setup / is needed. This is not as bad for me as for others since I'll simply try to get into the system, but for people not programming that long that want to contribute this could be a little problem :)

And also Contribution Guidelines would make it easier for others to contribute some code.

This is not critical or something, but it would be very useful for developers.

Doesnt work in Android

Can't see napchart nor the sidebar in android. Probably because svg isnt suppported?

So it would be good if server detected if browser can render it, and if not, gives a png file instead so atleast its viewable

Improve readability of charts on thumbnails created by crawlers

I am generating napchart thumbnails using this API:
https://napchart.com/api/getImage?chartid=e1sml&width=600&height=600&shape=circle

Before, when inserting these thumbnails inline into Discord using MessageEmbed, the text on the length of time allotted for naps was readable. This allowed the napchart to be understood even by looking at the thumbnail. Now, it is only very barely legible. In order to comfortably see the times you are forced to open the chart in your browser. This is quite a large usability regression.

Side by side comparison:
Thumbnail comparison

It would be great for you to increase the font size at least to the point where the thumbnail is readable.

Initialise MySQL database and table

If the database will be used a lot more perhaps an ORM would be a good idea:

Otherwise:

### ERROR  { [Error: ER_NO_SUCH_TABLE: Table 'napchart.chart' doesn't exist]
  code: 'ER_NO_SUCH_TABLE',
  errno: 1146,
  sqlState: '42S02',
  index: 0 }

/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Parser.js:82
        throw err;
              ^
Error: ER_NO_SUCH_TABLE: Table 'napchart.chart' doesn't exist
    at Query.Sequence._packetToError (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
    at Query.ErrorPacket (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
    at Protocol._parsePacket (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:274:23)
    at Parser.write (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Parser.js:77:12)
    at Protocol.write (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/Connection.js:96:28)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    --------------------
    at Protocol._enqueue (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:135:48)
    at Connection.query (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/Connection.js:201:25)
    at setChartID (/Users/gianfranco/temp/napchart.com/script.js:170:14)
    at Object.app.post.text [as handle] (/Users/gianfranco/temp/napchart.com/script.js:193:12)
    at next_layer (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/route.js:103:13)
    at Route.dispatch (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/route.js:107:5)
    at c (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:195:24)
    at Function.proto.process_params (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:251:12)
    at next (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:189:19)
    at next (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:166:38)

Snap to every 5 minutes [setting]

For some users it is easier to move things with a 5 minute interval.

This could be achieved by adding a settings element in the settings module and modify the snap function in interactCanvas

setting custom url doesn't work

Example:
I wanted to save this schedule under the name:
https://napchart.com/lionman,
but sadly it gave me the less descriptive url:
https://napchart.com/dui9k

Having that field be editable sets up an expectation,
that's subverted here.
Not sure, why editing the url is possible in the first place.
Maybe, make that a bit more obvious?
In any case, being able to set custom-urls would be awesome.

Adding More Colors/Sections

It would be very handy to be able to add more colors to the napchart, such as instead of their being the set grey, blue, green. There could just be a plus button and the ability to set a color based on the color wheel/pallet. This would allow for the setting of more activities, for instance on my napchart https://napchart.com/7glsb I would have liked to have four colors, with the fourth being a set time for fasting.

RESTful API

Any way to generate napchart schedules programically?

I've been thinking of making a discord chat bot for the reddit polyphasic group. A user could type a text representation of a schedule and the bot would output a napchart link. (for the graphical one)
Looking at the code, at the moment it only seems possible to do so with a forked, self-hosted version?

If napchart computes the chart ID (http://napchart.com/XXXXX) based on the schedule times rather than it being randomly generated, pointing to a code behind it would help a lot.

EDIT: Found it! This may be more difficult to implement than I expected though, as it involves querring the SQL database.

napchart/database.js

Lines 92 to 98 in 8fe511e

function idgen(){
alphabet = "abcdefghijklmnopqrstuwxyz0123456789";
id='';
for( var i=0; i < 5; i++ )
id += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
return id;
}

Move all sleep simoultaniously

This is a feature many people miss from the previous napchart version

Make a switch in the settings panel that links all sleep elements (nap,core) together so that they can be moved simoultainiously while retaining the same distances.

Cant export to pdf on mobile

When trying to save as pdf on Iphone 6s, it does not work.

Chrome: Opens a new about:blank with nothing
Safari: Nothing happens

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.