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

gojs-vue

v1.0.1

Published

A Vue component to manage GoJS Diagrams

Downloads

31,757

Readme

gojs-vue

GitHub package.json version

Based on GoJS 2.1

This project provides A Vue component for GoJS Diagrams to simplify usage of GoJS within a Vue application. the implementation of this project is inspired by gojs-react.

Installation

gojs-vue can be installed via NPM. This package has peer dependencies on gojs and vue-property-decorator, so make sure those are also installed or included on your application.

NPM

npm install --save gojs-vue

Usage

This package provides one component - VueDiagram - corresponding to the related GoJS classes.

<template>
  <VueDiagram
    divClassName='vue-diagram'
    :initDiagram="initDiagram"
    :nodeDataArray="nodeDataArray"
    :linkDataArray="linkDataArray"
    :modelData="modelData"
    @modelChange="handleModelChange"
  />
</template>

Component Props

initDiagram

Specifies a function that is reponsible for initializing and returning a GoJS Diagram. This is where the model and templates should be instantiated. Node and link data do not need to be set up here, as they will be passed in as separate props.

initDiagram() {
  const $ = go.GraphObject.make
  const diagram = $(go.Diagram, {
    'undoManager.isEnabled': true,
    model: $(go.GraphLinksModel, {
      linkKeyProperty: 'key'
    })
  })
  diagram.nodeTemplate = $(go.Node, 'Auto',
    $(go.Shape, 'RoundedRectangle', { strokeWidth: 0, fill: 'white', portId: '', fromLinkable: true, toLinkable: true, cursor: 'pointer' },
      new go.Binding('fill', 'color')),
    $(go.TextBlock, {
      margin: 8,
      font: 'bold 14px sans-serif',
      stroke: '#333'
    },
    new go.Binding('text', 'key'))
  )

  diagram.linkTemplate = $(go.Link,
    new go.Binding('relinkableFrom', 'canRelink').ofModel(),
    new go.Binding('relinkableTo', 'canRelink').ofModel(),
    $(go.Shape),
    $(go.Shape, { toArrow: 'Standard' })
  )

  return diagram
}

nodeDataArray

Specifies the array of nodes for the Diagram's model.

nodeDataArray: [
  { key: 'Alpha', color: 'lightblue' },
  { key: 'Beta', color: 'orange' },
  { key: 'Gamma', color: 'lightgreen' },
  { key: 'Delta', color: 'pink' }
]

Optional - divClassName

Specifies the CSS classname to add to the rendered div. The default style of rendered div is:

<style scoped>
.gojs-diagram {
  position: relative;
  width: 100%;
  height: 100%;
}
</style>

Optional - linkDataArray

Specifies the array of links for the Diagram's model, only needed when using a GraphLinksModel, not for Models or TreeModels. If using a GraphLinksModel, make sure to set the GraphLinksModel's linkKeyProperty in the init function.

linkDataArray: [
  { key: -1, from: 'Alpha', to: 'Beta' },
  { key: -2, from: 'Alpha', to: 'Gamma' },
  { key: -3, from: 'Beta', to: 'Beta' },
  { key: -4, from: 'Gamma', to: 'Delta' },
  { key: -5, from: 'Delta', to: 'Alpha' }
]

Optional - modelData

Specifies a modelData object for the Diagram's model, only necessary when using properties that will be shared by the model as a whole. See Model.modelData.

modelData: {
  canRelink: true
}

onModelChange

Specifies a function to be called when a GoJS transaction has completed.

handleModelChange(data) {
  const insertedNodeKeys = data.insertedNodeKeys
  const modifiedNodeData = data.modifiedNodeData
  const removedNodeKeys = data.removedNodeKeys
  const insertedLinkKeys = data.insertedLinkKeys
  const modifiedLinkData = data.modifiedLinkData
  const removedLinkKeys = data.removedLinkKeys

  // ... make state changes
}

License

This project is intended to be used alongside GoJS, and is covered by the GoJS software license