几行代码生成流程图

在看网上一些文章的时候,发现他们做的图都挺吃力的。。有得甚至就用文字符号拼凑而成,所以萌发做这样一个工具的念头。

开发背景

语言:Node.js

工具名: jsToDiagram (未上传)

使用例子

做一个例子,代码如下:

import jsToDiagram from './jsToDiagram'; 

const config = {
	savePath: './test.png',
	showPoint: false,//是否显示连接点
}

var mvcDiagram = new jsToDiagram(config);

//Sample 0
var wakeBlock = mvcDiagram.create('block','睡醒');
var prettyBlock = mvcDiagram.create('block','去吃拉麵');
var judgeBlock = mvcDiagram.create('Judge','加辣嗎');
var noeatBlock = mvcDiagram.create('block','好好吃');
var eatBlock = mvcDiagram.create('block','好辣啊');
var hotelBlock = mvcDiagram.create('block','吃飽睡覺');

wakeBlock.singleLink(prettyBlock);
prettyBlock.judge(judgeBlock,eatBlock,noeatBlock);
eatBlock.singleLink(hotelBlock);
noeatBlock.singleLink(hotelBlock);

mvcDiagram.draw((err) =>{
	if (err)throw err;
	console.log('Draw done')
});

然后就可以生成如下的流程图:

然后再试一个MVC的示意图

var modelBlock = mvcDiagram.create('block','model');
var controllerBlock = mvcDiagram.create('block','controller');
var viewBlock = mvcDiagram.create('block','view');
modelBlock.doubleLink(controllerBlock);
controllerBlock.doubleLink(viewBlock);
viewBlock.doubleLink(modelBlock);

mvcDiagram.draw((err) =>{
	if (err)throw err;
	console.log('Draw done')
});

生成图如下:

打包测试

刚写完的小工具,先整理下代码就发个测试版本到npm吧,然后之后就是要重构下算法。

 

 

 

转载于:https://my.oschina.net/u/203607/blog/1795262

展开阅读全文
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符

下面这些代码的流程图

05-19
@param httpRequest * @param order 订单实例 * @return * @throws Exception */ Public static String makeOrderAlipayUrl(HttpServletRequest httpRequest, Order order) throws Exception { HashMap hm = new HashHap(); hm. put(“_input_charset”, httpRequest.getCharacterEncoding()); //采用相同的编码方式 hm.put(“body”, “你在www.xxx.com上的订单”); //填写在跳到支付宝页面上显示的付款内容信息 hm.put(“discount”, “-5”); //填写折扣信息,-5表示抵扣5元 hm.put(“logistics_fee”, “10”); //物流费用 hm.put(“logistics_payment”, “BUYER_PAY”); //物流费用支付人,BUYER_PAY = 买家支付物流费用 hm.put(“logistics_type”, “EXPRESS”); //物流方式 hm.put(“notify_url”, “http://www.xxx.com/notifyurl.jsp”); //客户付款后,支付宝调用的页面 hm.put(“out_trade_no”, “order.getId()); //外部交易号,最好具有唯一性,在获取支付宝发来的付款信息时使用 hm.put(“partner”, partnerId); //partnerId(合作伙伴ID) hm.put(“agent”, partnerId); //partnerId(合作伙伴ID) hm.put(“payment_type”, “1”); //支付类型,l = 商品购买,2 = 服务购买,… hm.put(“price”, “105.30”); //订单金额信息 hm.put(“quantity”, “1”); //订单商品数量,一般都写1,即按照整个订单包来计算 hm.put(“return_url”, “http://www.xxx.com/ReturnUrl.jsp”); //客户付款成功后,显示给客户的页面 hm.put(“seller_email”, “alipay@xxx.com”); //你的支付宝账户E-mail hm.put(“service”, “create_direct_pay_by_user”); //create_direct_pay by_user = 直接付款,trade_create_by_buyer = 担保付款 hm.put(“subject”, “www.xxx.com的订单”); //填写跳到支付宝页面上后显示的付款标题信息 String payGateway = “https://www.alipay.com/cooperate/gateway.do?”; //跳转到支付宝的url头 return makeUrl(hm, securityCode, httpRequest.getCharacterEncoding(), payGateway); //securityCode(安全码) } /* * 根据传入的参数生成alipay的支付URL * @param hm 参数值 * @param securityCode 安全码 * @param charset 编码 * @param payGateway 支付宝 gateway * @return */ Public static String makeUrl(HashMap hm, String securityCode, String charset, String payGateway) throws Exception{ List keys = new ArrayList(hm.keySet()); Collections.sort(keys); //支付宝要求参数必须按字母排序 StringBuffer content = new StringBuffer(); For (int i = 0; i < keys.size(); i++) { content.append((String) keys.get(i)); content.append(“=”); content.append((String) hm.get((String) keys.get(i))); if (i != keys.size() - 1) { content.append(“&”); } } Content.append(securityCode); String Sign = md5(content.toString(), charset); content.delete(0, content.1ength()); content.append(payGateway); for (int i = 0; i < keys.size(); i++) { content.append(keys.get(i)); content.append(“=”); content.append(URLEncoder.encode((String) hm.get(keys.get(i)), charset)); content.append(“&”); } content.append(“sign=”); content.append(sign); content.append(“&sign_type=MD5”); keys.clear(); keys = null; return content.toString(); } /* * 生成md5编码字符串 * @param str 源字符串 * @param charset 编码方式 * @return */ Public static String md5(String str, String charset) { if (str == null) return null; char hexdigits[] = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’}; MessageDigest md5MesageDigest = null; byte[] md5Bytes = null; char md5Chars[] = null; byte[] strBytes = null; try { strBytes = str.getbytes(charset); md5MessageDigest = MessageDigest.getInstance(“MD5”); md5MessageDigest.update(strBytes); md5Bytes = md5MessageDigest.digest (); int j = md5Bytes.length; md5Chars = new char [j*2]; int k = 0; for (int i = 0; i < j; i++) { byte md5Byte = md5Bytes[i]; md5Chars[k++] = hexDigests [md5Byte >>> 4 & 0xf]; md5Chars[k++] = hexDigests [md5Byte & 0xf]; } return new String(md5Chars); } catch (NoSuchAlgorithmException e) { //Log.output(e.toString(), Log.STD_ERR); return null; } catch (UnsupportedEncodingException e) { //Log.output(e.toString(), Log.STD_ERR); return null; } finally { md5MessageDigest = null; strBytes = null; md5Bytes = null;
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值