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

compass-rose-ui

v1.2.1

Published

a javascript control for selecting velocity and direction for wind and water.

Downloads

78

Readme

compass-rose-ui

Compass Rose UI is a javascript control for selecting velocity and direction for wind and water.

It has been designed as a jquery plugin and as such can be easily embedded anywhere(within reason) in an HTML document.

Here's what it looks like.

![Image of compass-rose-ui] (https://raw.githubusercontent.com/NOAA-ORR-ERD/compass-rose-ui/master/ui_screenshot.png)

###So How do I Use it??### The following is a quick illustration that should tell you pretty much everything you need to know to put a compass-rose UI control into your web page. It wouldn't hurt though, to understand some of the fundamentals of jquery.

===

First, the .js source needs to be included in the head of the document. Below is a snippet of what it might look like...

  <head>
    ...
    <script src="/static/js/compass-rose-ui.min.js"></script>
    ...
  </head>

The URL for the source file will likely change depending on where you decide to locate it. The above example assumes it is located on the same webserver that is serving the web page.

=== Next, you can optionally set some styles for the control...

    <style type="text/css" >
      ...

      #const-wind-1 {
        width: 300px;
        height: 300px;
        position: relative;
      }

      ...
    </style>

Here, we are setting the style for an instance of our ui called 'const-wind-1'.

=== The next thing to do is define an instance of our compass-rose-ui. This is done in kinda the standard way you would invoke any jquery-ui control...

  <script type="text/javascript" >
    window.onload = function() {
      ...

      $('#const-wind-1').compassUI({
        'arrow-direction': 'in',
        'move': function( magnitude, direction ) {
          $( "#const-wind-speed" ).val(magnitude.toFixed(2));
          $( "#const-wind-dir" ).val(direction.toFixed(2));
          $( "#const-wind-cdir" ).val( this["cardinal-name"](direction));
        },
        'change': function( magnitude, direction ) {
          $('#wind-directions').find('tbody:last').empty();
          $('#wind-directions').find('tbody:last').append(
            '<tr>' +
            '<td>' + '</td>' +
            '<td>' + '</td>' +
            '<td>' + $( '#const-wind-speed' ).val() + ' ' + $( '#const-wind-speed-units' ).val() + '</td>' +
            '<td>' + $( '#const-wind-dir' ).val() + '</td>' +
            '<td>' + $( '#const-wind-cdir' ).val() + '</td>' +
            '</tr>'
          );
        },
      });

      ...
    };

  </script>

It is a good idea to do this after the window is rendered. Here, we do this by defining it inside window.onload. A couple things to notice about this definition:

  • 'arrow-direction' is visually the direction the arrow is pointing on the compass
  • 'move' is the function that is invoked when the arrow is 'dragged'. You can define this function to do just about anything with the magnitude and direction args.
  • 'change' is similar to move, but it is invoked when an arrow move operation is completed. (i.e. the arrow is dragged and then released).

=== ####Optional#### There are a couple of convenience functions built-in to each compass control that are used to convert angular direction values into their associated cardinal direction and vice versa.

Here is a short snippet that illustrates these functions...

  <script type="text/javascript" >
    ...

    var cardinal_value = 'ne';  // for example

    var angle = $('#const-wind-1')[0].settings['cardinal-angle'](cardinal_value);
    DoSomethingWithTheAngle(angle);

    var direction_value = 45.0;  // for example

    var cardinal = $('#const-wind-1')[0].settings['cardinal-name'](direction_value);
    DoSomethingWithTheCardinal(cardinal);

    ...
  </script>

=== ####Finally#### The last thing to do now is put it into the body of your web page. The way to do that is simply define a <div> tag with the id of the instance you defined.

  <div id="const-wind-1">
  </div>