mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-04 06:39:40 +02:00
Add interpolateToCurve util method
This commit is contained in:
@@ -4,6 +4,7 @@ import * as d3 from 'd3'
|
|||||||
import db from './gitGraphAst'
|
import db from './gitGraphAst'
|
||||||
import gitGraphParser from './parser/gitGraph'
|
import gitGraphParser from './parser/gitGraph'
|
||||||
import { logger } from '../../logger'
|
import { logger } from '../../logger'
|
||||||
|
import { interpolateToCurve } from '../../utils'
|
||||||
|
|
||||||
let allCommitsDict = {}
|
let allCommitsDict = {}
|
||||||
let branchNum
|
let branchNum
|
||||||
@@ -52,10 +53,7 @@ function svgCreateDefs (svg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function svgDrawLine (svg, points, colorIdx, interpolate) {
|
function svgDrawLine (svg, points, colorIdx, interpolate) {
|
||||||
let curve = d3.curveBasis
|
const curve = interpolateToCurve(interpolate, d3.curveBasis)
|
||||||
if (interpolate === 'linear') {
|
|
||||||
curve = d3.curveLinear
|
|
||||||
}
|
|
||||||
const color = config.branchColors[colorIdx % config.branchColors.length]
|
const color = config.branchColors[colorIdx % config.branchColors.length]
|
||||||
const lineGen = d3.line()
|
const lineGen = d3.line()
|
||||||
.x(function (d) {
|
.x(function (d) {
|
||||||
@@ -73,6 +71,7 @@ function svgDrawLine (svg, points, colorIdx, interpolate) {
|
|||||||
.style('stroke-width', config.lineStrokeWidth)
|
.style('stroke-width', config.lineStrokeWidth)
|
||||||
.style('fill', 'none')
|
.style('fill', 'none')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass in the element and its pre-transform coords
|
// Pass in the element and its pre-transform coords
|
||||||
function getElementCoords (element, coords) {
|
function getElementCoords (element, coords) {
|
||||||
coords = coords || element.node().getBBox()
|
coords = coords || element.node().getBBox()
|
||||||
|
16
src/utils.js
16
src/utils.js
@@ -1,4 +1,4 @@
|
|||||||
import { logger } from './logger'
|
import * as d3 from 'd3'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function detectType
|
* @function detectType
|
||||||
@@ -36,12 +36,10 @@ export const detectType = function (text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text.match(/^\s*classDiagram/)) {
|
if (text.match(/^\s*classDiagram/)) {
|
||||||
logger.debug('Detected classDiagram syntax')
|
|
||||||
return 'classDiagram'
|
return 'classDiagram'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text.match(/^\s*gitGraph/)) {
|
if (text.match(/^\s*gitGraph/)) {
|
||||||
logger.debug('Detected gitGraph syntax')
|
|
||||||
return 'gitGraph'
|
return 'gitGraph'
|
||||||
}
|
}
|
||||||
return 'graph'
|
return 'graph'
|
||||||
@@ -61,7 +59,17 @@ export const isSubstringInArray = function (str, arr) {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const interpolates = {
|
||||||
|
basis: d3.curveBasis,
|
||||||
|
linear: d3.curveLinear,
|
||||||
|
cardinal: d3.curveCardinal
|
||||||
|
}
|
||||||
|
export const interpolateToCurve = (interpolate, defaultCurve) => {
|
||||||
|
return interpolates[interpolate] || defaultCurve
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
detectType,
|
detectType,
|
||||||
isSubstringInArray
|
isSubstringInArray,
|
||||||
|
interpolateToCurve
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user