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

dtd-diagram

v0.2.1

Published

Animated tree diagrams for XML DTDs

Downloads

6

Readme

Interactive, animated DTD schema diagrams

See the demo.

This is a D3 implementation of the old XML Near & Far diagrams. See this Key to the Near & Far Diagrams and the following pages, for examples of what Near & Far diagrams look like.

Contents

This page

Implementation

Current status and to-do list

Getting started

To run from your own machine, you can use Bower, and add this as a dependency:

bower install dtd-diagram --save

Or, you download it and its dependencies manually:

To integrate it with your own DTD, you'll want to clone it and initialize a development environment, which includes DtdAnalyzer, used to convert DTDs into the JSON files that this tool consumes.

Make sure you have Node.js and npm installed, and then install gulp globally (if you haven't already). This makes the gulp command available on the command line:

npm install -g gulp

Then clone the repo, and build it:

git clone https://github.com/Klortho/dtd-diagram.git
cd dtd-diagram
npm install
gulp

Check that it worked, by bringing up the project folder in a web browser.

To generate JSON versions of DTDs, you'll need to set your PATH to include the vendor/dtd-analyzer directory, and then, for example, for the test DTD:

dtdanalyzer --roots doc --xslt daz2json.xsl test/test2.dtd > test2.json 

To work with one of the JATS DTDs, you could do this:

dtdanalyzer --roots article --xslt daz2json.xsl \
  http://jats.nlm.nih.gov/publishing/1.1d3/JATS-journalpublishing1.dtd \
  > JATS-journalpublishing1.json

Then, in the HTML file that invokes the diagram, set options to load the correct DTD JSON file, and to cause documentation hyperlinks to go to the right place. (see the index.html page for an example):

<div id='dtd-diagram'
     data-options='{
         "dtd_json_file": "JATS-journalpublishing1.json",
         "tag_doc_base": "http://jatspan.org/niso/publishing-1.1d3/#p="
     }'></div>

To work on the JavaScript modules, and have gulp watch for changes, and automatically build the combined, minified files, start a watcher in a terminal with:

gulp watch

API

The simplest way to use this is to load the code in a page that has a pre-existing <div> element with id value "dtd-diagram". For example:

<head>
  ...
  <link rel="stylesheet" type="text/css" href="dtd-diagram.css">
  <script src='es6-promise.js'></script>
  <script src="d3.min.js"></script>
  <script src="d3-flextree.js"></script>
  <script src="dtd-diagram.js"></script>
  ...
</head>
<body>
  ...
  <div id='dtd-diagram'></div>
  ...
</body>

By default, if you include the JavaScript in your HTML page, then a DtdDiagram will be instantiated at document ready, using all the default options. If you want to prevent this behavior, then set auto_start to false, before document ready. This will let you control when a diagram is created, based on (for example) user events. For example:

<head>
  ...
  <script type="text/javascript" src="dtd-diagram.js"></script>
  ...
</head>
<body>
  ...
  <div id='dtd-diagram'></div>
  <input id='button' type='button' />
  ...
  <script type="text/javascript">
    DtdDiagram.auto_start = false;
    ...
    $('#button').on("click", function() {
      new DtdDiagram();
    };
  </script>
</body>

If you create your own diagram object before document ready, that will also suppress the auto-creation. This allows you to easily override default options. For example,

<script type="text/javascript" src="dtd-diagram.js"></script>
<script type="text/javascript">
  new DtdDiagram({
    duration: 5000,
  });
</script>

You can also set options on the <div> element, in the data-options attribute, in valid JSON format.

<div id='dtd-diagram'
     data-options='{"root_element": "back"}'>
</div>

You can get a list of all of the diagrams on a page from DtdDiagram.diagrams.

Options

FIXME: need to update this list.

There are various ways to set the options; in order of higher-to-lower precedence:

  • Pass them as an object to the DtdDiagram constructor function.
  • Set them on the @data-options attribute of the <div> element. Make sure they are in strictly valid JSON format.
  • Use the defaults

dtd_json_file

The DTD JSON file; default is "dtd.json".

root_element

The root element, by default, is read from the DTD file, but can be overridden. Default is null.

tag_doc_base

Used as the base URL for links from the element and attribute nodes to documentation. Default is "doc/#p=".

tag_doc_url

By default, this is not used. You can set this to a function that takes a Node object as an argument, and returns a string with the URL of the documentation page.

min_canvas_width, min_canvas_height

Initial value for the diagram's size.

group_separation

Ratio of the separation between groups to the separation between sibling nodes. By default, this is 1.4.

duration

Duration of the animation, in milliseconds. Default is 500.

rebase_handler

You can set this to a callback function that will be invoked whenever the user rebases the diagram.

Implementation

See Implementation.md

Credits / references

License

See LICENSE.txt.