Skip to content
Snippets Groups Projects
Commit 6e023a03 authored by Behrisch, M. (Michael)'s avatar Behrisch, M. (Michael)
Browse files

fix: :rocket: remodels mock-data location and access

Several (potentially even external) libraries might want
to use our mock data and some utils. I pulled them
out into a lib with a package.json
parent 15b61e80
No related branches found
No related tags found
1 merge request!13merge develop into main
Showing
with 350 additions and 94 deletions
......@@ -19,9 +19,7 @@
},
"build": {
"executor": "@nrwl/web:webpack",
"outputs": [
"{options.outputPath}"
],
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"compiler": "babel",
......@@ -35,18 +33,18 @@
"apps/web-graphpolaris/src/favicon.ico",
"apps/web-graphpolaris/src/assets"
],
"styles": [
"apps/web-graphpolaris/src/styles.scss"
],
"styles": ["apps/web-graphpolaris/src/styles.scss"],
"scripts": [],
"webpackConfig": "@nrwl/react/plugins/webpack"
},
"configurations": {
"production": {
"fileReplacements": [{
"replace": "apps/graphpolaris/src/environments/environment.ts",
"with": "apps/graphpolaris/src/environments/environment.prod.ts"
}],
"fileReplacements": [
{
"replace": "apps/graphpolaris/src/environments/environment.ts",
"with": "apps/graphpolaris/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
......@@ -71,20 +69,14 @@
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": [
"{options.outputFile}"
],
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"apps/graphpolaris/**/*.{ts,tsx,js,jsx}"
]
"lintFilePatterns": ["apps/graphpolaris/**/*.{ts,tsx,js,jsx}"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": [
"coverage/apps/graphpolaris"
],
"outputs": ["coverage/apps/graphpolaris"],
"options": {
"jestConfig": "apps/web-graphpolaris/jest.config.js",
"passWithNoTests": true
......@@ -113,9 +105,7 @@
},
"build-storybook": {
"executor": "@nrwl/storybook:build",
"outputs": [
"{options.outputPath}"
],
"outputs": ["{options.outputPath}"],
"options": {
"uiFramework": "@storybook/react",
"outputPath": "dist/storybook/graphpolaris",
......@@ -131,4 +121,4 @@
}
},
"tags": []
}
\ No newline at end of file
}
import { SchemaFromBackend } from '@graphpolaris/shared/data-access/store';
import { SchemaFromBackend } from '@graphpolaris/models';
import { SchemaUtils } from '@graphpolaris/schema-utils';
import { MultiGraph } from 'graphology';
import { parse } from 'path/posix';
import { parseSchemaFromBackend } from '..';
import { Attributes } from 'graphology-types';
import {
movieSchema,
northWindSchema,
simpleSchema,
twitterSchema,
movieSchemaRaw,
northwindSchemaRaw,
simpleSchemaRaw,
twitterSchemaRaw,
} from 'libs/shared/mock-data/src';
describe('SchemaUsecases', () => {
test.each([
{ data: simpleSchema },
{ data: movieSchema },
{ data: northWindSchema },
{ data: twitterSchema },
{ data: simpleSchemaRaw },
{ data: movieSchemaRaw },
{ data: northwindSchemaRaw },
{ data: twitterSchemaRaw },
])('parseSchemaFromBackend parsing should work', ({ data }) => {
// console.log('testinput', input);
const parsed = parseSchemaFromBackend(data as SchemaFromBackend);
const parsed = SchemaUtils.ParseSchemaFromBackend(
data as SchemaFromBackend
);
expect(parsed).toBeDefined();
let parsedNodeAttributes: Attributes[] = [];
......@@ -52,17 +53,19 @@ describe('SchemaUsecases', () => {
});
it('should export and reimport', () => {
const parsed = parseSchemaFromBackend(simpleSchema as SchemaFromBackend);
const parsed = SchemaUtils.ParseSchemaFromBackend(
simpleSchemaRaw as SchemaFromBackend
);
const reload = MultiGraph.from(parsed.export());
expect(parsed).toStrictEqual(reload);
});
test.each([
{ data: simpleSchema },
{ data: movieSchema },
{ data: northWindSchema },
{ data: twitterSchema },
{ data: simpleSchemaRaw },
{ data: movieSchemaRaw },
{ data: northwindSchemaRaw },
{ data: twitterSchemaRaw },
])('should load my test json $data', ({ data }) => {
expect(data).toBeDefined();
expect(data.nodes).toBeDefined();
......
......@@ -181,32 +181,32 @@ export function createReactFlowElements(graph: Graph): Elements<Node | Edge> {
return initialElements;
}
export function parseSchemaFromBackend(
schemaFromBackend: SchemaFromBackend
): Graph {
const { nodes, edges } = schemaFromBackend;
// Instantiate a directed graph that allows self loops and parallel edges
const schemaGraph = new MultiGraph({ allowSelfLoops: true });
// console.log('parsing schema');
// The graph schema needs a node for each node AND edge. These need then be connected
nodes.forEach((node) => {
schemaGraph.addNode(node.name, {
name: node.name,
attributes: node.attributes,
x: 0,
y: 0,
});
});
// export function parseSchemaFromBackend(
// schemaFromBackend: SchemaFromBackend
// ): Graph {
// const { nodes, edges } = schemaFromBackend;
// // Instantiate a directed graph that allows self loops and parallel edges
// const schemaGraph = new MultiGraph({ allowSelfLoops: true });
// // console.log('parsing schema');
// // The graph schema needs a node for each node AND edge. These need then be connected
// nodes.forEach((node) => {
// schemaGraph.addNode(node.name, {
// name: node.name,
// attributes: node.attributes,
// x: 0,
// y: 0,
// });
// });
// The name of the edge will be name + from + to, since edge names are not unique
edges.forEach((edge) => {
const edgeID = [edge.name, '_', edge.from, edge.to].join(''); //ensure that all interpreted as string
// // The name of the edge will be name + from + to, since edge names are not unique
// edges.forEach((edge) => {
// const edgeID = [edge.name, '_', edge.from, edge.to].join(''); //ensure that all interpreted as string
// This node is the actual edge
schemaGraph.addDirectedEdgeWithKey(edgeID, edge.from, edge.to, {
attribute: edge.attributes,
});
});
return schemaGraph;
}
// // This node is the actual edge
// schemaGraph.addDirectedEdgeWithKey(edgeID, edge.from, edge.to, {
// attribute: edge.attributes,
// });
// });
// return schemaGraph;
// }
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from './store';
import Graph, { MultiGraph } from 'graphology';
import { SchemaFromBackend } from 'libs/shared/models/src';
/*************** schema format from the backend *************** */
// TODO: should probably not live here
/** Schema type, consist of nodes and edges */
export type SchemaFromBackend = {
edges: Edge[];
nodes: Node[];
};
/** Attribute type, consist of a name */
export type Attribute = {
name: string;
type: 'string' | 'int' | 'bool' | 'float';
};
/** Node type, consist of a name and a list of attributes */
export type Node = {
name: string;
attributes: Attribute[];
};
/** Edge type, consist of a name, start point, end point and a list of attributes */
export type Edge = {
name: string;
to: string;
from: string;
collection: string;
attributes: Attribute[];
};
/**************************************************************** */
// Define the initial state using that type
......
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
{
"extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
# shared-graph-layout
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test shared-graph-layout` to execute the unit tests via [Jest](https://jestjs.io).
module.exports = {
displayName: 'shared-graph-layout',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../../coverage/libs/shared/graph-layout',
};
{
"systemParams": "win32-x64-83",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [
"graphology-generators@^0.11.2",
"graphology-layout-forceatlas2@^0.8.2",
"graphology-layout-noverlap@^0.4.2",
"graphology-layout@^0.5.0",
"graphology@^0.24.1"
],
"lockfileEntries": {
"@yomguithereal/helpers@^1.1.1": "https://registry.yarnpkg.com/@yomguithereal/helpers/-/helpers-1.1.1.tgz#185dfb0f88ca2beec53d0adf6eed15c33b1c549d",
"events@^3.3.0": "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400",
"graphology-generators@^0.11.2": "https://registry.yarnpkg.com/graphology-generators/-/graphology-generators-0.11.2.tgz#eff2c97e4f5bf401e86ab045470dded95f2ebe24",
"graphology-indices@^0.16.3": "https://registry.yarnpkg.com/graphology-indices/-/graphology-indices-0.16.6.tgz#0de112ef0367e44041490933e34ad2075cb24e80",
"graphology-layout-forceatlas2@^0.8.2": "https://registry.yarnpkg.com/graphology-layout-forceatlas2/-/graphology-layout-forceatlas2-0.8.2.tgz#7cb5b2fa00fd5445cb2b73c333e36ef22c8a82a8",
"graphology-layout-noverlap@^0.4.2": "https://registry.yarnpkg.com/graphology-layout-noverlap/-/graphology-layout-noverlap-0.4.2.tgz#2ffa054ceeebaa31fcffe695d271fc55707cd29c",
"graphology-layout@^0.5.0": "https://registry.yarnpkg.com/graphology-layout/-/graphology-layout-0.5.0.tgz#a0a54861cebae5f486c778dbdafc6294859f23b5",
"graphology-metrics@^2.0.0": "https://registry.yarnpkg.com/graphology-metrics/-/graphology-metrics-2.1.0.tgz#7d00bae92d8970583afd020e6d40d8a16c378002",
"graphology-shortest-path@^2.0.0": "https://registry.yarnpkg.com/graphology-shortest-path/-/graphology-shortest-path-2.0.0.tgz#27a01b3a9980872bd44a197fc77114623dd2b302",
"graphology-utils@^2.1.0": "https://registry.yarnpkg.com/graphology-utils/-/graphology-utils-2.5.1.tgz#93916ead84ec7896959b4033b94cd6994ae9952c",
"graphology-utils@^2.3.0": "https://registry.yarnpkg.com/graphology-utils/-/graphology-utils-2.5.1.tgz#93916ead84ec7896959b4033b94cd6994ae9952c",
"graphology-utils@^2.4.2": "https://registry.yarnpkg.com/graphology-utils/-/graphology-utils-2.5.1.tgz#93916ead84ec7896959b4033b94cd6994ae9952c",
"graphology-utils@^2.4.3": "https://registry.yarnpkg.com/graphology-utils/-/graphology-utils-2.5.1.tgz#93916ead84ec7896959b4033b94cd6994ae9952c",
"graphology-utils@^2.4.4": "https://registry.yarnpkg.com/graphology-utils/-/graphology-utils-2.5.1.tgz#93916ead84ec7896959b4033b94cd6994ae9952c",
"graphology@^0.24.1": "https://registry.yarnpkg.com/graphology/-/graphology-0.24.1.tgz#035e452e294b01168cf5c85d5dd0a4b7e4837d87",
"mnemonist@^0.39.0": "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.39.0.tgz#4c83dd22e8d9d05dfb721ff66a905fec4c460041",
"obliterator@^2.0.1": "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.2.tgz#25f50dc92e1181371b9d8209d11890f1a3c2fc21",
"obliterator@^2.0.2": "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.2.tgz#25f50dc92e1181371b9d8209d11890f1a3c2fc21",
"pandemonium@^1.5.0": "https://registry.yarnpkg.com/pandemonium/-/pandemonium-1.5.0.tgz#93f35af555de1420022b341e730215c51c725be3"
},
"files": [],
"artifacts": {}
}
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2018 Guillaume Plique (Yomguithereal)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[![Build Status](https://travis-ci.org/Yomguithereal/helpers.svg)](https://travis-ci.org/Yomguithereal/helpers)
# Yomguithereal's helpers
Miscellaneous helper functions.
## Installation
```
npm install @yomguithereal/helpers
```
## Usage
* [#.extend](#extend)
## #.extend
Pushes multiple values to the given array.
It is faster than doing `array.push.apply(array, values)` and works by first mutating the array's length and then setting the new indices (benchmark proved it is faster than a loop of pushes).
```js
import extend from '@yomguithereal/helpers/extend';
const a = [1, 2, 3];
extend(a, [4, 5, 6]);
a
>>> [1, 2, 3, 4, 5, 6]
```
export default function extend<T>(array: Array<T>, values: Array<T>): void;
/**
* Extend function
* ================
*
* Function used to push a bunch of values into an array at once.
*
* Its strategy is to mutate target array's length then setting the new indices
* to be the values to add.
*
* A benchmark proved that it is faster than the following strategies:
* 1) `array.push.apply(array, values)`.
* 2) A loop of pushes.
* 3) `array = array.concat(values)`, obviously.
*
* Intuitively, this is correct because when adding a lot of elements, the
* chosen strategies does not need to handle the `arguments` object to
* execute #.apply's variadicity and because the array know its final length
* at the beginning, avoiding potential multiple reallocations of the underlying
* contiguous array. Some engines may be able to optimize the loop of push
* operations but empirically they don't seem to do so.
*/
/**
* Extends the target array with the given values.
*
* @param {array} array - Target array.
* @param {array} values - Values to add.
*/
module.exports = function extend(array, values) {
var l2 = values.length;
if (l2 === 0)
return;
var l1 = array.length;
array.length += l2;
for (var i = 0; i < l2; i++)
array[l1 + i] = values[i];
};
export {default as extend} from './extend';
/**
* Miscellaneous helper functions.
* ================================
*
* Library endpoint.
*/
exports.extend = require('./extend.js');
{
"name": "@yomguithereal/helpers",
"version": "1.1.1",
"description": "Miscellaneous helper functions.",
"main": "index.js",
"files": [
"*.d.ts",
"*.js"
],
"types": "./index.d.ts",
"scripts": {
"lint": "eslint **/*.js",
"prepublish": "npm run lint && npm test",
"test": "mocha test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Yomguithereal/helpers.git"
},
"author": {
"name": "Guillaume Plique",
"url": "http://github.com/Yomguithereal"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/Yomguithereal/helpers/issues"
},
"homepage": "https://github.com/Yomguithereal/helpers#readme",
"devDependencies": {
"@yomguithereal/eslint-config": "^4.0.0",
"eslint": "^7.10.0",
"mocha": "^8.1.3"
},
"eslintConfig": {
"extends": "@yomguithereal/eslint-config"
}
}
/**
* Helpers Unit Tests
* ===================
*/
var assert = require('assert'),
lib = require('./');
describe('#.extend', function() {
it('should correctly extend the given array.', function() {
var A = [1, 2, 3],
B = [4, 5, 6];
lib.extend(A, B);
assert.strictEqual(A.length, 6);
assert.strictEqual(B.length, 3);
assert.deepEqual(A, [1, 2, 3, 4, 5, 6]);
});
});
sauce_connect: true
loopback: airtap.local
browsers:
- name: chrome
version: latest
- name: firefox
version: latest
- name: safari
version: 9..latest
- name: iphone
version: latest
- name: ie
version: 9..latest
- name: microsoftedge
version: 13..latest
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/events
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
dist: xenial
os: linux
language: node_js
node_js:
- 'stable'
- 'lts/*'
- '0.12'
script:
- npm test
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_NODE_VERSION}" = "stable" ]; then npm run test:browsers; fi
addons:
sauce_connect: true
hosts:
- airtap.local
env:
global:
- secure: XcBiD8yReflut9q7leKsigDZ0mI3qTKH+QrNVY8DaqlomJOZw8aOrVuX9Jz12l86ZJ41nbxmKnRNkFzcVr9mbP9YaeTb3DpeOBWmvaoSfud9Wnc16VfXtc1FCcwDhSVcSiM3UtnrmFU5cH+Dw1LPh5PbfylYOS/nJxUvG0FFLqI=
- secure: jNWtEbqhUdQ0xXDHvCYfUbKYeJCi6a7B4LsrcxYCyWWn4NIgncE5x2YbB+FSUUFVYfz0dsn5RKP1oHB99f0laUEo18HBNkrAS/rtyOdVzcpJjbQ6kgSILGjnJD/Ty1B57Rcz3iyev5Y7bLZ6Y1FbDnk/i9/l0faOGz8vTC3Vdkc=
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment