Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it an NPM package. #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// eslint-disable-next-line no-undef
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-unused-vars":0,
"no-prototype-builtins": 0,
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

node_modules


# C extensions
*.so

Expand Down
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,116 @@

# cti-stix-visualization

## Installation

D3 is required as a peer dependency.

TODO POSSIBLY UPDATE

```
npm i cti-stix-to-vis
```

## Basic Use


```js
import d3 from "d3";
import initViz from "cti-stix-to-viz";


const Viz = initViz(d3);

const vizInstance = new Viz(document.getElementById("my-svg"), {
id: "my-svg"
});

vizInstance.vizStix(testData, {
//config
});

```


## Example usage with React:


TODO probably a good idea to add a link to code-sandbox

```jsx
import React, { useEffect, useRef } from 'react';
import './App.css';

import { testData } from './testData';
import d3 from "d3";


//TODO UPDATE THIS
import initViz from "cti-stix-visualization-dwj";


const Viz = initViz(d3);


function App() {

const svgRef = useRef<SVGSVGElement>(null);
useEffect(() => {

console.log(svgRef);
if (svgRef.current) {
const vizInstance = new Viz(svgRef.current, {
id: 'foo',

});

vizInstance.vizStix(testData, {}, (...args) => {
console.log("vizCallBack", args);
}, (...args) => {
console.log("errorCallback", args)
});
}
}, [svgRef]);
return (
<div className="App" >
<svg ref={svgRef} id='foo'></svg>
</div>
);
}

export default App;

```


## Local use


Install dependencies

```
yarn
```

Build the compiled code (required for local server)

```
yarn build
```

Start local server

```
yarn start
```

Open your browser to http://localhost:3000






*This is an [OASIS TC Open Repository](https://www.oasis-open.org/resources/open-repositories/). See the [Governance](#governance) section for more information.*

The STIX visualization is meant to provide producers and consumers of STIX content with a rapid way to visualize the objects in a STIX JSON file, and the relationships between those objects. The visualization is implemented in HTML, CSS, and JavaScript (using the [D3.js](https://d3js.org/) library), and is suitable for standalone use — either on a hosted server or as a local file — or embedded into other applications. Regardless of how deployed, the JavaScript code in this repository does not transmit STIX data to any server; it is strictly processed within the browser in which the code is running, so it is suitable for data which the user does not wish to share.
Expand Down
4 changes: 1 addition & 3 deletions application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ require.config({
}
});

require(["domReady!", "stix2viz/stix2viz/stix2viz"], function (document, stix2viz) {


require(["domReady!", "stix2viz/stix2viz/stix2viz", "lib/stix2vizcore"], function (document, stix2viz) {
// Init some stuff
// For optimization purposes, look into moving these to local variables
var visualizer;
Expand Down
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "cti-stix-visualization-dwj",
"version": "0.0.1",
"main": "lib/stix2vizcore.js",
"repository": "git@github.com:dwjohnston/cti-stix-visualization.git",
"author": "David Johnston <david@blacksheepcode.com>",
"license": "SEE LICNESE",
"scripts": {
"clean": "rm -rf lib",
"build": "tsc",
"start": "serve .",
"lint": "eslint ./stix2viz/stix2viz/stix2viz.js"
},
"peerDependencies": {
"d3": "^3.5.14"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"d3": "^3.5.14",
"eslint": "^8.12.0",
"serve": "^13.0.2",
"typescript": "^4.6.3"
}
}
Loading