Skip to content

Commit

Permalink
update setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Jun 7, 2020
1 parent 9e73410 commit 406fd5c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"dist",
"src/**/*.ts"
],
"browserslist": [
"Firefox ESR",
"last 2 Chrome versions",
"last 2 Firefox versions"
],
"dependencies": {
"@types/cytoscape": "^3.14.3"
},
Expand Down
5 changes: 4 additions & 1 deletion rollup.dts.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import dts from 'rollup-plugin-dts';
import fs from 'fs';

const pkg = JSON.parse(fs.readFileSync('./package.json'));

export default {
input: './.tmp/index.d.ts',
output: {
file: 'dist/index.d.ts',
format: 'es',
},
externals: ['cytoscape', 'bubblesets-js'],
external: Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {})),
plugins: [
dts({
respectExternal: true,
Expand Down
20 changes: 10 additions & 10 deletions src/BubbleSetPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NodeCollection, EdgeCollection, NodeSingular, BoundingBoxWH, BoundingBox12, EdgeSingular } from 'cytoscape';
import cy from 'cytoscape';
import {
IOutlineOptions,
PointPath,
Expand Down Expand Up @@ -35,12 +35,12 @@ export interface ICanvasStyle {
strokeStyle?: string | CanvasGradient | CanvasPattern;
}

export interface IBubbleSetNodeData {
interface IBubbleSetNodeData {
area?: Area;
isCircle: boolean;
shape: Circle | Rectangle;
}
export interface IBubbleSetEdgeData {
interface IBubbleSetEdgeData {
lines: Line[];
areas: Area[];
}
Expand Down Expand Up @@ -68,7 +68,7 @@ function linesEquals(a: ILine[], b: ILine[]) {
return a.length === b.length && a.every((ai, i) => toEdgeKey(ai) === toEdgeKey(b[i]));
}

function createShape(isCircle: boolean, bb: BoundingBox12 & BoundingBoxWH) {
function createShape(isCircle: boolean, bb: cy.BoundingBox12 & cy.BoundingBoxWH) {
return isCircle
? new Circle(bb.x1 + bb.w / 2, bb.y1 + bb.h / 2, Math.max(bb.w, bb.h) / 2)
: new Rectangle(bb.x1, bb.y1, bb.w, bb.h);
Expand All @@ -85,9 +85,9 @@ export default class BubbleSetPath {

constructor(
private readonly plugin: { draw(): void; removePath(path: BubbleSetPath): boolean },
public readonly nodes: NodeCollection,
public readonly edges: EdgeCollection | null,
public readonly avoidNodes: NodeCollection | null,
public readonly nodes: cy.NodeCollection,
public readonly edges: cy.EdgeCollection | null,
public readonly avoidNodes: cy.NodeCollection | null,
options: IBubbleSetPathOptions = {}
) {
this.options = Object.assign(
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class BubbleSetPath {
}

let updateEdges = false;
const updateNodeData = (n: NodeSingular) => {
const updateNodeData = (n: cy.NodeSingular) => {
const bb = n.boundingBox(this.options);
let data = (n.scratch(SCRATCH_KEY) ?? null) as IBubbleSetNodeData | null;
const isCircle = isCircleShape(n.style('shape'));
Expand Down Expand Up @@ -206,7 +206,7 @@ export default class BubbleSetPath {

if (!potentialAreaDirty) {
this.virtualEdgeAreas.forEach((value, key) => edgeCache.set(key, value));
(this.edges ?? []).forEach((n: EdgeSingular) => {
(this.edges ?? []).forEach((n: cy.EdgeSingular) => {
const data = (n.scratch(SCRATCH_KEY) ?? null) as IBubbleSetEdgeData | null;
if (data && data.lines) {
data.lines.forEach((line, i) => {
Expand All @@ -229,7 +229,7 @@ export default class BubbleSetPath {
};
const edges: Area[] = [];

(this.edges ?? []).forEach((e: EdgeSingular) => {
(this.edges ?? []).forEach((e: cy.EdgeSingular) => {
const ps = (e.segmentPoints() ?? [e.sourceEndpoint(), e.targetEndpoint()]).map((d) => Object.assign({}, d));
if (ps.length === 0) {
return;
Expand Down
12 changes: 6 additions & 6 deletions src/BubbleSetsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Core, EdgeCollection, NodeCollection } from 'cytoscape';
import cy from 'cytoscape';
import throttle from 'lodash.throttle';
import BubbleSetPath, { IBubbleSetPathOptions } from './BubbleSetPath';

Expand All @@ -14,7 +14,7 @@ export default class BubbleSetsPlugin {
private readonly pixelRatio: number;
private readonly paths: BubbleSetPath[] = [];

constructor(private readonly cy: Core, private readonly options: IBubbleSetsPluginOptions = {}) {
constructor(private readonly cy: cy.Core, private readonly options: IBubbleSetsPluginOptions = {}) {
const container = cy.container();

const canvas = (this.canvas = (container?.ownerDocument ?? document).createElement('canvas'));
Expand Down Expand Up @@ -53,9 +53,9 @@ export default class BubbleSetsPlugin {
}

addPath(
nodes: NodeCollection,
edges: EdgeCollection | null,
avoidNodes: NodeCollection | null,
nodes: cy.NodeCollection,
edges: cy.EdgeCollection | null,
avoidNodes: cy.NodeCollection | null,
options: IBubbleSetPathOptions = {}
) {
const path = new BubbleSetPath(this, nodes, edges, avoidNodes, Object.assign({}, this.options, options));
Expand Down Expand Up @@ -107,6 +107,6 @@ export default class BubbleSetsPlugin {
}
}

export function bubbleSets(this: Core, options: IBubbleSetsPluginOptions = {}) {
export function bubbleSets(this: cy.Core, options: IBubbleSetsPluginOptions = {}) {
return new BubbleSetsPlugin(this, options);
}
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"target": "ES2020",
"module": "ESNext",
"lib": ["DOM", "ES2020"],
"importHelpers": false,
"declaration": false,
"sourceMap": true,
"strict": true,
Expand Down
7 changes: 5 additions & 2 deletions tsdx.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const commonjs = require('@rollup/plugin-commonjs');
const resolve = require('rollup-plugin-pnp-resolve');
const cleanup = require('rollup-plugin-cleanup');
const fs = require('fs');

const pkg = JSON.parse(fs.readFileSync('./package.json'));

module.exports = {
rollup(config, options) {
Expand All @@ -9,9 +12,9 @@ module.exports = {
// }

config.output.globals['cytoscape'] = 'cytoscape';
config.output.globals['bubblesets-js'] = 'BubbleSets';
const base = config.external;
config.external = (v) => v === 'cytoscape';
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
config.external = (v) => (base(v) ? external.includes(v) : false);

const c = config.plugins.findIndex((d) => d.name === 'commonjs');
if (c !== -1) {
Expand Down

0 comments on commit 406fd5c

Please sign in to comment.