Skip to content

Commit

Permalink
feat: trim the node label (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMercy235 committed Apr 4, 2020
1 parent 855859a commit 8b97d86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/shared/constants/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ export const GRAPH_DEFAULT_CONFIG = {
export const GRAPH_ENABLE_PREVIEW_LOCAL_STORAGE = 'isPreviewEnabled';

export const GRAPH_PREVIEW_TIMEOUT = 1000;

export const GRAPH_NAME_MAX_LENGTH = 30;
10 changes: 8 additions & 2 deletions src/shared/utils/graphUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeColors } from '../utilities';
import { GRAPH_NODE_SIZE, GraphLinkTypes, GraphNodeLabelPositions } from '../constants/graph';
import { GRAPH_NAME_MAX_LENGTH, GRAPH_NODE_SIZE, GraphLinkTypes, GraphNodeLabelPositions } from '../constants/graph';
import { OptionModel } from '../../infrastructure/models/OptionModel';

export const NodeSymbol = {
Expand All @@ -21,6 +21,12 @@ export const generateRandomPosition = () => {
};
};

const getNodeLabel = label => {
return label.length < GRAPH_NAME_MAX_LENGTH
? label
: `${label.substring(0, GRAPH_NAME_MAX_LENGTH)}...`;
};

export const seqToNode = (story, selectedNode) => seq => {
const position = seq.x && seq.y
? { x: seq.x, y: seq.y }
Expand All @@ -30,7 +36,7 @@ export const seqToNode = (story, selectedNode) => seq => {
id: seq._id,
...position,
size: GRAPH_NODE_SIZE,
name: seq.name,
name: getNodeLabel(seq.name),
...(story.startSeq === seq._id && {
symbolType: NodeSymbol.Wye,
color: ThemeColors.Primary,
Expand Down

0 comments on commit 8b97d86

Please sign in to comment.