# topology-viewer2

> Topology Viewer component library

Latest version **0.0.20** (published 2018-08-24) · 0 weekly downloads

## Install

```sh
npm install topology-viewer2
pnpm add topology-viewer2
yarn add topology-viewer2
bun add topology-viewer2
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.20 |
| Published | 2018-08-24 |
| First published | 2018-08-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 330.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shu Tang |
| Maintainers | sltang |
| Keywords | react, component, topology, viewer |

## Links

- npm: https://www.npmjs.com/package/topology-viewer2
- Repository: https://sparksource.collaboration.agilent.com/scm/siddev/topology-report
- npm.io page: https://npm.io/package/topology-viewer2

## Dependencies (11)

- [d3](https://npm.io/package/d3.md) ^5.5.0
- [asn1](https://npm.io/package/asn1.md) ^0.2.4
- [rxjs](https://npm.io/package/rxjs.md) ^6.2.2
- [react](https://npm.io/package/react.md) ^16.4.2
- [@types/d3](https://npm.io/package/@types/d3.md) ^5.0.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.4.2
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.6.0
- [rxjs-compat](https://npm.io/package/rxjs-compat.md) ^6.2.2
- [@material-ui/core](https://npm.io/package/@material-ui/core.md) ^1.4.3
- [@material-ui/icons](https://npm.io/package/@material-ui/icons.md) ^2.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.20 (latest) — 2018-08-24
- 0.0.19 — 2018-08-23
- 0.0.18 — 2018-08-20
- 0.0.17 — 2018-08-20
- 0.0.16 — 2018-08-10
- 0.0.15 — 2018-08-10
- 0.0.12 — 2018-08-06
- 0.0.11 — 2018-08-06
- 0.0.10 — 2018-08-06
- 0.0.9 — 2018-08-06
- 0.0.8 — 2018-08-06
- 0.0.7 — 2018-08-06
- 0.0.6 — 2018-08-06
- 0.0.5 — 2018-08-06
- 0.0.4 — 2018-08-03
- … 3 more at https://npm.io/package/topology-viewer2/versions

## README

# Topology Report
It is a React component for the Topology Report. It is transpiled with Babel and bundled with Rollup. It can be published to a NPM registry (public or private) which can then be imported by React or Angular applications. It requires BootStrap 4 to work properly. 

To install dependencies:
`npm install`

To run tests:
`npm test`

To build:
`npm run build`

This builds the component in the build directory.

To publish to a npm registry:
`npm publish`

To install it from npm after publishing:
`npm install topology-viewer2`

## Integration with Angular
1. Create an Angular component wrapper.
```
import {TopologyViewer} from 'topology-viewer2/build';
...

export class TopologyViewerComponent implements AfterViewInit {

    @Input()
    public content = '';

    constructor(private router: Router, private hostRef: ElementRef) {
      this.onComputerTableClick=this.onComputerTableClick.bind(this)
      this.onInstrumentTableClick=this.onInstrumentTableClick.bind(this)
    }

    ngAfterViewInit(): void {
      this.render();
    }

    onComputerTableClick(name:string) : void {
      this.router.navigate(['computer-details', name]);
    }

    onInstrumentTableClick(name:string) : void {
      this.router.navigate(['instrument-details', name]);
    }

    private render(): void {
      const hostElement = this.hostRef.nativeElement;
      const tvElement = React.createElement(TopologyViewer, {
          handleComputerTableClick : this.onComputerTableClick,
          handleInstrumentTableClick : this.onInstrumentTableClick
        }, this.content)    
      ReactDOM.render(tvElement, hostElement)  
  }

}
```
2. Create ComputerDetailsComponent:
```
import {ComputerDetails} from 'topology-viewer2/build';
...
export class ComputerDetailsComponent implements AfterViewInit, OnInit {

    name : string

    @Input()
    public content = '';

    constructor(private router: Router, private route: ActivatedRoute, private hostRef: ElementRef) {
      this.onNodeClick=this.onNodeClick.bind(this)
    }

    ngOnInit() {
      this.name = this.route.snapshot.paramMap.get('name')
    }

    ngAfterViewInit(): void {      
      this.render();
    }

    onNodeClick(name:string) : void {
      this.router.navigate(['instrument-details', name]);
    }

    private render(): void {
      const hostElement = this.hostRef.nativeElement;
      const computerDetails = React.createElement(ComputerDetails,  
        {match:{params:{name:this.name}}, 
        handleNodeClick:this.onNodeClick}, 
        this.content)     
      ReactDOM.render(computerDetails, hostElement)  
  }
  ```
3. Create InstrumentDetailsComponent in a similar manner.
4. Add routes to the RoutingModule that route 'computer-details' to ComputerDetailsComponent and 'instrument-details' to InstrumentDetailsCoomponent. (Adjust the paths accordingly.)

---
_Source: https://npm.io/package/topology-viewer2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
