Commit 5ce63474 authored by 张博's avatar 张博

add resource bgcolor, close fex-team/kityminder-editor#87

parent a902f05e
...@@ -10,6 +10,10 @@ define(function(require, exports, module) { ...@@ -10,6 +10,10 @@ define(function(require, exports, module) {
Module.register('Resource', function() { Module.register('Resource', function() {
// String Hash
// https://github.com/drostie/sha3-js/edit/master/blake32.min.js
var blake32=(function(){var k,g,r,l,m,o,p,q,t,w,x;x=4*(1<<30);k=[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19];m=[0x243F6A88,0x85A308D3,0x13198A2E,0x03707344,0xA4093822,0x299F31D0,0x082EFA98,0xEC4E6C89,0x452821E6,0x38D01377,0xBE5466CF,0x34E90C6C,0xC0AC29B7,0xC97C50DD,0x3F84D5B5,0xB5470917];w=function(i){if(i<0){i+=x}return("00000000"+i.toString(16)).slice(-8)};o=[[16,50,84,118,152,186,220,254],[174,132,249,109,193,32,123,53],[139,12,37,223,234,99,23,73],[151,19,205,235,98,165,4,143],[9,117,66,250,30,203,134,211],[194,166,176,56,212,87,239,145],[92,241,222,164,112,54,41,184],[189,231,28,147,5,79,104,162],[246,158,59,128,44,125,65,90],[42,72,103,81,191,233,195,13]];p=function(a,b,n){var s=q[a]^q[b];q[a]=(s>>>n)|(s<<(32-n))};g=function(i,a,b,c,d){var u=l+o[r][i]%16,v=l+(o[r][i]>>4);a%=4;b=4+b%4;c=8+c%4;d=12+d%4;q[a]+=q[b]+(t[u]^m[v%16]);p(d,a,16);q[c]+=q[d];p(b,c,12);q[a]+=q[b]+(t[v]^m[u%16]);p(d,a,8);q[c]+=q[d];p(b,c,7)};return function(a,b){if(!(b instanceof Array&&b.length===4)){b=[0,0,0,0]}var c,d,e,L,f,h,j,i;d=k.slice(0);c=m.slice(0,8);for(r=0;r<4;r+=1){c[r]^=b[r]}e=a.length*16;f=(e%512>446||e%512===0)?0:e;if(e%512===432){a+="\u8001"}else{a+="\u8000";while(a.length%32!==27){a+="\u0000"}a+="\u0001"}t=[];for(i=0;i<a.length;i+=2){t.push(a.charCodeAt(i)*65536+a.charCodeAt(i+1))}t.push(0);t.push(e);h=t.length-16;j=0;for(l=0;l<t.length;l+=16){j+=512;L=(l===h)?f:Math.min(e,j);q=d.concat(c);q[12]^=L;q[13]^=L;for(r=0;r<10;r+=1){for(i=0;i<8;i+=1){if(i<4){g(i,i,i,i,i)}else{g(i,i,i+1,i+2,i+3)}}}for(i=0;i<8;i+=1){d[i]^=b[i%4]^q[i]^q[i+8]}}return d.map(w).join("")}}());
/** /**
* 自动使用的颜色序列 * 自动使用的颜色序列
*/ */
...@@ -17,19 +21,33 @@ define(function(require, exports, module) { ...@@ -17,19 +21,33 @@ define(function(require, exports, module) {
return kity.Color.createHSL(h, 100, 85); return kity.Color.createHSL(h, 100, 85);
}); });
var RESOURCE_COLOR_OVERFLOW = kity.Color.createHSL(0, 0, 95);
/** /**
* 在 Minder 上拓展一些关于资源的支持接口 * 在 Minder 上拓展一些关于资源的支持接口
*/ */
kity.extendClass(Minder, { kity.extendClass(Minder, {
/**
* 获取字符串的哈希值
*
* @param {String} str
* @return {Number} hashCode
*/
getHashCode: function(str) {
str = blake32(str);
var hash = 1315423911, i, ch;
for (i = str.length - 1; i >= 0; i--) {
ch = str.charCodeAt(i);
hash ^= ((hash << 5) + ch + (hash >> 2));
}
return (hash & 0x7FFFFFFF);
},
/** /**
* 获取脑图中某个资源对应的颜色 * 获取脑图中某个资源对应的颜色
* *
* 如果存在同名资源,则返回已经分配给该资源的颜色,否则分配给该资源一个颜色,并且返回 * 如果存在同名资源,则返回已经分配给该资源的颜色,否则分配给该资源一个颜色,并且返回
* *
* 如果资源数超过颜色序列数量,返回 * 如果资源数超过颜色序列数量,返回哈希颜
* *
* @param {String} resource 资源名称 * @param {String} resource 资源名称
* @return {Color} * @return {Color}
...@@ -44,8 +62,8 @@ define(function(require, exports, module) { ...@@ -44,8 +62,8 @@ define(function(require, exports, module) {
colorMapping[resource] = nextIndex; colorMapping[resource] = nextIndex;
} }
// 资源过多,找不到可用索引颜色,统一返回 // 资源过多,找不到可用索引颜色,统一返回哈希函数得到的颜
return RESOURCE_COLOR_SERIES[colorMapping[resource]] || RESOURCE_COLOR_OVERFLOW; return RESOURCE_COLOR_SERIES[colorMapping[resource]] || kity.Color.createHSL(Math.floor(this.getHashCode(resource) / 0x7FFFFFFF * 359), 100, 85);
}, },
/** /**
...@@ -107,14 +125,10 @@ define(function(require, exports, module) { ...@@ -107,14 +125,10 @@ define(function(require, exports, module) {
/** /**
* @command Resource * @class 设置资源的命令
* @description 设置节点的资源标签
* @param {Array<string>} resource 要设置的资源列表,设置为空清除节点的资源标签
* @return 返回当前选中节点中包含的资源(数组)
* *
* @example * @example
* *
* ```js
* // 设置选中节点资源为 "张三" * // 设置选中节点资源为 "张三"
* minder.execCommand('resource', ['张三']); * minder.execCommand('resource', ['张三']);
* *
...@@ -125,7 +139,6 @@ define(function(require, exports, module) { ...@@ -125,7 +139,6 @@ define(function(require, exports, module) {
* *
* // 清除选中节点的资源 * // 清除选中节点的资源
* minder.execCommand('resource', null); * minder.execCommand('resource', null);
* ```
*/ */
var ResourceCommand = kity.createClass('ResourceCommand', { var ResourceCommand = kity.createClass('ResourceCommand', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment