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

kodiagram

v0.2.1

Published

A set of components to create svg diagrams using knockout

Downloads

5

Readme

knockout-diagram

An es6 client-side library for creating svg diagrams using knockout. It requires knockout and jQuery (these aren't bundled).

Currently it only supports a small number of primitive shapes, but it can easily be extended.

Introduction

Simple example:

  function ViewModel() {
    this.shapes = ko.observableArray([
      new kodiagram.Circle("Animal", 0, 40, 40),
      new kodiagram.Rect("Dog", 100, 40, 100, 80),
      new kodiagram.Rect("Cat", 70, 140, 80, 80)
    ]);
  }
  ko.applyBindings(new ViewModel());
  <svg height="300" width="300" class="kd">
    <!-- ko foreach: shapes -->
      <g data-bind="template: { name: templateName, svg: true }" />
    <!-- /ko -->
  </svg>

This will render two rectangles and a circle, along with their given labels. You can change the positions/parameters of these shapes in the view model, and these changes will automatically be reflected in the DOM:

  var circle = this.shapes[0];
  circle.moveTo(20, 20);

  // Or set the values directly:
  circle.x(20);
  circle.y(20);

  // Alter dimensions:
  circle.xradius(200);

  // Change the label:
  circle.text("New label");

The x, y and xradius members are observables that are bound to the DOM. E.g. the template for a circle is:

  <script type="text/html" id="kd-shape-circle">
    <g data-bind="attr: { transform: tPosition }">
      <circle data-bind="attr: { cx: xradius, cy: xradius, r: xradius }" />
      <text data-bind="attr: { x: xradius, y: xradius }, text: text" text-anchor="middle" dy="0.3em" />
    </g>
  </script>

The shape templates are now defined within the library, so there's no need to define these in your project markup.

Note that knockout doesn't support svg out of the box because it's a html library. This project replaces the native knockout template engine with a one that also supports svg.

Installation

Clone the repo and build the js module using npm, grunt and babel:

git clone https://github.com/CodeOverload/kodiagram.git
cd kodiagram
npm install
npm run build

This builds dist/kodiagram.esm.js and dist/kodiagram.umd.js

Getting Started

See example/example.html

Knockout SVG support

To a certain extent, knockout works for svg - but only when the svg elements are already in the DOM (e.g. when you bind the attributes of an existing svg element in the DOM to a view model). If knockout is creating the svg elements, the elements get added to the DOM but they don't get rendered. This is because knockout creates the elements as HTMLElement objects, and not SVGElements (such as SVGCircleElement). To get around this, I've wrote a new knockout template engine that also supports svg. Essentially this creates SVG elements if the svg: true option is specified in the template reference (see the example above).