1 | import * as d3 from 'd3'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export const detectType = function (text) {
|
21 | text = text.replace(/^\s*%%.*\n/g, '\n')
|
22 | if (text.match(/^\s*sequenceDiagram/)) {
|
23 | return 'sequence'
|
24 | }
|
25 |
|
26 | if (text.match(/^\s*gantt/)) {
|
27 | return 'gantt'
|
28 | }
|
29 |
|
30 | if (text.match(/^\s*classDiagram/)) {
|
31 | return 'class'
|
32 | }
|
33 |
|
34 | if (text.match(/^\s*gitGraph/)) {
|
35 | return 'git'
|
36 | }
|
37 | return 'flowchart'
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export const isSubstringInArray = function (str, arr) {
|
48 | for (let i = 0; i < arr.length; i++) {
|
49 | if (arr[i].match(str)) return i
|
50 | }
|
51 | return -1
|
52 | }
|
53 |
|
54 | export const interpolateToCurve = (interpolate, defaultCurve) => {
|
55 | if (!interpolate) {
|
56 | return defaultCurve
|
57 | }
|
58 | const curveName = `curve${interpolate.charAt(0).toUpperCase() + interpolate.slice(1)}`
|
59 | return d3[curveName] || defaultCurve
|
60 | }
|
61 |
|
62 | export default {
|
63 | detectType,
|
64 | isSubstringInArray,
|
65 | interpolateToCurve
|
66 | }
|