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

Fix/defensive code for curve types #115

Merged
merged 2 commits into from Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions sandbox/utils.js
@@ -1,11 +1,26 @@
/*eslint require-jsdoc: 0, valid-jsdoc: 0, no-undef: 0, no-empty: 0, no-console: 0*/
import queryString from 'query-string';
import { LINE_TYPES } from '../src/components/link/link.const';

/**
* This two functions generate the react-jsonschema-form
* schema from some passed graph configuration.
*/
function formMap(k, v) {
// customized props
switch (k) {
case 'link.type': {
return {
type: 'array',
title: 'link.type',
items: {
enum: Object.keys(LINE_TYPES)
},
uniqueItems: true
};
}
}

return {
title: k,
type: typeof v,
Expand Down
3 changes: 2 additions & 1 deletion src/components/link/link.helper.js
Expand Up @@ -71,7 +71,8 @@ function getRadiusStrategy(type) {
function buildLinkPathDefinition({ source = {}, target = {} }, type = LINE_TYPES.STRAIGHT) {
const { x: sx, y: sy } = source;
const { x: tx, y: ty } = target;
const radius = getRadiusStrategy(type)(sx, sy, tx, ty);
const validType = LINE_TYPES[type] || LINE_TYPES.STRAIGHT;
const radius = getRadiusStrategy(validType)(sx, sy, tx, ty);

return `M${sx},${sy}A${radius},${radius} 0 0,1 ${tx},${ty}`;
}
Expand Down