From 9c101eb8afaab666b94a98fb22868bfb93194207 Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Fri, 9 Mar 2018 13:33:35 +0800 Subject: [PATCH] Add interpolateToCurve util method --- src/diagrams/gitGraph/gitGraphRenderer.js | 7 +++---- src/utils.js | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/diagrams/gitGraph/gitGraphRenderer.js b/src/diagrams/gitGraph/gitGraphRenderer.js index 06fd5b673..8392c9ce1 100644 --- a/src/diagrams/gitGraph/gitGraphRenderer.js +++ b/src/diagrams/gitGraph/gitGraphRenderer.js @@ -4,6 +4,7 @@ import * as d3 from 'd3' import db from './gitGraphAst' import gitGraphParser from './parser/gitGraph' import { logger } from '../../logger' +import { interpolateToCurve } from '../../utils' let allCommitsDict = {} let branchNum @@ -52,10 +53,7 @@ function svgCreateDefs (svg) { } function svgDrawLine (svg, points, colorIdx, interpolate) { - let curve = d3.curveBasis - if (interpolate === 'linear') { - curve = d3.curveLinear - } + const curve = interpolateToCurve(interpolate, d3.curveBasis) const color = config.branchColors[colorIdx % config.branchColors.length] const lineGen = d3.line() .x(function (d) { @@ -73,6 +71,7 @@ function svgDrawLine (svg, points, colorIdx, interpolate) { .style('stroke-width', config.lineStrokeWidth) .style('fill', 'none') } + // Pass in the element and its pre-transform coords function getElementCoords (element, coords) { coords = coords || element.node().getBBox() diff --git a/src/utils.js b/src/utils.js index 57c244210..bde3a8712 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,4 +1,4 @@ -import { logger } from './logger' +import * as d3 from 'd3' /** * @function detectType @@ -36,12 +36,10 @@ export const detectType = function (text) { } if (text.match(/^\s*classDiagram/)) { - logger.debug('Detected classDiagram syntax') return 'classDiagram' } if (text.match(/^\s*gitGraph/)) { - logger.debug('Detected gitGraph syntax') return 'gitGraph' } return 'graph' @@ -61,7 +59,17 @@ export const isSubstringInArray = function (str, arr) { return -1 } +const interpolates = { + basis: d3.curveBasis, + linear: d3.curveLinear, + cardinal: d3.curveCardinal +} +export const interpolateToCurve = (interpolate, defaultCurve) => { + return interpolates[interpolate] || defaultCurve +} + export default { detectType, - isSubstringInArray + isSubstringInArray, + interpolateToCurve }