microscopium / microscopium-ui

Microscopium web interface.
2 stars 4 forks source link

Add byteflag utility class #76

Closed starcalibre closed 8 years ago

starcalibre commented 8 years ago

The new fast canvas based scatterplot I've been working on has involved the creation of a few new functions and classes, so I thought I'd merge these in iteratively to make the process a bit easier.

One big disadvantage to using the canvas to draw plots is you can't save state in the DOM -- the current scatterplot manages details such as which is the active sample, which is being filtered out, etc using CSS classes. You don't get this convenience with the canvas, so you need your own way to manage the state of each element being drawn.

JS supports C-style bit manipulation, so I've been managing the state of each sample using a byteflag. A Number is attached to every sample and is treated as a byteflag. e.g. samples with value 0x01 are the actively selected point, samples with 0x02 are neighbour points, etc. Whenever the plot drawing method is called, the current state of each sample can be read from the byteflag so the point can be drawn with the appropriate stylings. I thought this was the best way to go because it elegantly handles multiple states for each point while only using a single Number to do so.

Bit manipulation syntax is dog ugly and easy to make mistakes with so this PR ads a few methods to make bit manipulation easier. It also moves all the utility classes to a utils folder. Tests for great justice included too. :D

starcalibre commented 8 years ago

@jni Just checking you got the notification for this one? :)

jni commented 8 years ago

@starcalibre I did but been stupid busy with book and such... Will look later today... Maybe ping me again though... =)

jni commented 8 years ago

@starcalibre some very minor comments. =)

starcalibre commented 8 years ago

@jni thanks, should be good to go now !