@@ -6,7 +6,7 @@
<!-- { { hexagonTextPos . data ? hexagonTextPos . data . nums : '' } } -- >
<!-- < / span > -- >
<!-- < / div > -- >
< div id= "hexagonSvg" >
< div : id= "hexagonSvgID " >
< / div >
< / div >
@@ -15,24 +15,21 @@
< script >
import { SVG } from '@svgdotjs/svg.js'
import '@svgdotjs/svg.panzoom.js'
let hexagonSvg = null ; / / S v g 的 实 例
let domSvg = null ; / / S v g 的 d o m 用 来 控 制 缩 放
let svgPolyline = null / / S v g h e x a g o n 的 边 框
let allHexagonText = [ ] ;
import { getHexagon , setHexagon , delHexagon } from "../js/common" ;
function hexagonEnter ( ) { / / 移 入 六 边 形
let level = this . first ( ) . data ( 'level ' ) ;
let color = level === 'P1' ? '#FFCDCD' : ( level === 'P2' ? '#FFE0B8' : '#B2ECD9' ) ;
let color = this . first ( ) . data ( 'hoverColor ' ) ;
this . first ( ) . animate ( 100 ) . stroke ( { width : 3 , color : '#909090' } ) . fill ( color ) ;
this . animate ( 100 ) . transform ( { scale : 1.1 } ) ;
svgP olyline. animate ( 100 ) . stroke ( { color : '#909090' } )
this . parent ( ) . find ( 'p olyline' ) . animate ( 100 ) . stroke ( { color : '#909090' } )
/ / s v g P o l y l i n e . a n i m a t e ( 1 0 0 ) . s t r o k e ( { c o l o r : ' # 9 0 9 0 9 0 ' } )
}
function hexagonLeave ( ) { / / 移 出 六 边 形
let level = this . first ( ) . data ( 'level ' ) ;
let color = level === 'P1' ? '#FAAFAF' : ( level === 'P2' ? '#FFCF92' : '#99D7C2' ) ;
let color = this . first ( ) . data ( 'color ' ) ;
this . first ( ) . animate ( 100 ) . stroke ( { width : 0 , color : '#909090' } ) . fill ( color ) ;
this . animate ( 100 ) . transform ( { scale : 1 } ) ;
svgP olyline. animate ( 100 ) . stroke ( { color : '#DADADA' } )
this . parent ( ) . find ( 'p olyline' ) . animate ( 100 ) . stroke ( { color : '#DADADA' } )
/ / s v g P o l y l i n e . a n i m a t e ( 1 0 0 ) . s t r o k e ( { c o l o r : ' # D A D A D A ' } )
}
function hexagonPoint ( x , y , edge ) { / / 根 据 左 上 角 坐 标 点 生 成 六 边 的 六 个 点 的 坐 标 通 过 s v g 画 出
@@ -74,7 +71,7 @@
}
}
function borderMove ( left , top , borderSize , type ) { / / l e f t , t o p , 坐 标 b o r d e r S i z e 长 度 , t y p e 外 层 边 框 线 从 哪 走 到 那
function borderMove ( left , top , borderSize , type , svgPolyline ){ / / l e f t , t o p , 坐 标 b o r d e r S i z e 长 度 , t y p e 外 层 边 框 线 从 哪 走 到 那
let point = [ null , null ] ;
let MathSqrt3 = Math . sqrt ( 3 ) ;
let arr = svgPolyline . array ( ) ;
@@ -111,39 +108,90 @@
export default {
name : "hexagonFigureSvg" ,
props : {
hexData : { } ,
col : { } ,
length : { }
hexData : { } , / / 数 据
hexagonSvgID : { / / 在 同 一 个 页 面 创 建 多 个 实 例 时 需 要 通 过 i d 区 分
type : String ,
default : 'hexagonSvg' ,
} ,
col : { } , / / 列 数
colorFrom : { / / 通 过 什 么 决 定 颜 色
type : String ,
default : '' ,
} ,
infoSet : { / / 设 置 六 边 形 内 部 内 容 参 数 g r o u p 对 应 六 边 形 所 在 的 组 。 a l l H e x a g o n R e c t 吧 所 有 文 本 框 放 入 , 方 便 控 制 显 示 隐 藏 。 d a t a 六 边 形 的 相 关 数 d a t a . c e n t e r 中 心 点 。 t h a t 子 组 件 实 例
type : Function ,
} ,
colorSet : { / / 设 置 方 块 对 应 颜 色 参 数 i t e m 当 前 i t e m 的 数 据
type : Function ,
default : ( ) => { return { color : '#99D7C2' , hoverColor : '#B2ECD9' } }
} ,
infoShow : { / / 设 置 六 边 形 内 部 内 容 放 大 显 示 时 的 样 式 参 数 a l l H e x a g o n R e c t
type : Function ,
} ,
infoHide : { / / 设 置 六 边 形 内 部 内 容 缩 小 显 示 时 的 样 式 参 数 a l l H e x a g o n R e c t
type : Function ,
} ,
hexagonEdge : { / / 边 框 长 度
type : Number ,
default : 90 ,
} ,
defaultRate : { / / 默 认 倍 率
type : Number ,
default : 0.33 ,
} ,
magnifyRate : { / / 放 大 倍 率
type : Number ,
default : 1 ,
} ,
isClickRate : { / / 是 否 支 持 点 击 放 大
type : Boolean ,
default : true ,
} ,
isPanning : { / / 是 否 支 持 移 动
type : Boolean ,
default : true ,
} ,
isPinchZoom : { / / 是 否 支 持 手 指 缩 放
type : Boolean ,
default : false ,
} ,
isWheelZoom : { / / 是 否 支 持 手 指 缩 放
type : Boolean ,
default : false ,
} ,
zoomFactor : { / / 鼠 标 滚 轮 放 大 倍 数
type : Number ,
default : 0.5 ,
} ,
zoomMin : { / / 最 小 倍 数
type : Number ,
default : 0.2 ,
} ,
zoomMax : { / / 最 小 倍 数
type : Number ,
default : 5 ,
}
} ,
watch : {
hexData : {
immediate : false ,
deep : true ,
handler ( ) {
handler ( n ) {
this . init ( ) ;
}
} ,
col : {
col : { / / 列 数
immediate : false ,
deep : true ,
handler ( ) {
this . init ( ) ;
}
} ,
length : {
immediate : false ,
deep : true ,
handler ( ) {
this . init ( ) ;
}
} ,
} ,
data ( ) {
return {
allHexagon : [ ] ,
allGroup : [ ] ,
hexagonEdge : 90 ,
/ / c o l : 5 ,
row : 5 ,
boxPadLeft : 360 ,
@@ -161,6 +209,7 @@
timer : null ,
boxhexagonShow : false ,
pan : false , / / 是 否 移 动
defaultColor : { color : '#99D7C2' , hoverColor : '#B2ECD9' } ,
}
} ,
computed : {
@@ -168,6 +217,8 @@
return ( this . hexagonEdge * this . MathSqrt3 / 5 ) * 0.5 ;
}
} ,
created ( ) {
} ,
mounted ( ) {
/ / t h i s . i n i t ( )
} ,
@@ -178,18 +229,24 @@
setTimeout ( ( ) => {
this . boxhexagonShow = true ;
this . $nextTick ( ( ) => {
this . hexagonData = JSON . parse ( JSON . stringify ( this . hexData . concat ( this . hexData , this . hexData ) )) ;
localStorage . setItem ( 'hexagonData' , JSON . stringify ( this . hexData . concat ( this . hexData , this . hexData , this . hexData , this . hexData , this . hexData , this . hexData ) ) ) ;
this . hexagonData = JSON . parse ( localStorage . getItem ( 'hexagonData' ) ) ;
this . hexagonData = this . hexagonData . slice ( 0 , this . length ) ;
hexagonSvg = SVG ( ) . addTo ( '#hexagonSvg' ) . size ( '100%' , '100%' )
. panZoom ( { zoomMin : 0.5 , zoomMax : 3 , zoomFactor : 0.3 , pinchZoom : false , wheelZoom : false } )
this . hexagonData = JSON . parse ( JSON . stringify ( this . hexData ) ) ;
let box = ` # ${ this . hexagonSvgID } ` ;
let hexagonSvg = SVG ( ) . addTo ( box ) . size ( '100%' , '100%' )
. panZoom ( {
zoomMin : this . zoomMin ,
zoomMax : this . zoomMax ,
zoomFactor : this . zoomFactor ,
pinchZoom : this . isPinchZoom ,
wheelZoom : this . isWheelZoom ,
panning : this . isPanning
} )
. attr ( 'id' , 'SvgHex' )
. attr ( 'class' , this . hexagonSvgID )
. attr ( 'viewBox' , ` 0 0 ${ this . $refs . box . offsetWidth } ${ this . $refs . box . offsetHeight } ` ) ; / / s v g 实 例
domSvg = document . getElementById ( 'SvgHex' ) ; / / s v g d o m
hexagonSvg . on ( 'click' , this . hexagonSvgClearScale ) ;
hexagonSvg . on ( 'panStart' , this . hexagonSvgPanStart ) ;
hexagonSvg . on ( 'panEnd' , this . hexagonSvgPanEnd ) ;
setHexagon ( this . hexagonSvgID , { hexagonSvg : hexagonSvg , svgPolyline : null , allHexagonRect : [ ] , allHexagonText : [ ] } )
this . getPadding ( ) . then ( ( ) => {
this . getDataPoint ( ) ;
} ) ; / / 获 取 到 上 方 和 左 方 的 距 离 ;
@@ -200,15 +257,23 @@
return new Promise ( resolve => {
let hexagonWidth = this . MathSqrt3 * this . hexagonEdge + this . interspace ;
let hexagonHeight = this . hexagonEdge * 2 + this . interspace ;
if ( this . hexagonData . length < this .col ) {
let row = parseInt ( ( this . hexagonData . length ) / ( this . col * 2 - 1 ) ) * 2 ; / / 行 数 是 总 数 除 2 倍 列 数 - 1 的 整 数 部 分 加 上 根 据 余 数 的 判 断
let dolNum = ( this . hexagonData . length ) % ( this . col * 2 - 1 )
if ( dolNum > 0 && dolNum <= this . col ) { / / 余 数 的 判 断
row += 1
} else if ( dolNum > 0 && dolNum > this . col ) {
row += 2
}
this . row = row ;
if ( this . hexagonData . length - 1 <= this . col ) {
/ / b o x P a d L e f t : 2 0 0 , b o x P a d T o p : 7 5 ,
this . boxPadLeft = ( this . $refs . box . offsetWidth - this . hexagonData . length * hexagonWidth ) / 2 ;
this . boxPadTop = ( this . $refs . box . offsetHeight - hexagonHeight ) / 2
this . boxPadTop = ( this . $refs . box . offsetHeight - hexagonHeight ) / 2 ; / / 只 有 一 行 是 到 上 方 距 离 应 该 是 两 倍 边 长
} else {
this . boxPadLeft = ( this . $refs . box . offsetWidth - this . col * hexagonWidth ) / 2 ;
this . boxPadTop = ( this . $refs . box . offsetHeight - hexagonHeight * ( Math . round ( this . hexagonData . length / ( this . col * 2 - 1 ) ) + 1 ) ) / 2
this . boxPadTop = ( this . $refs . box . offsetHeight - ( hexagonHeight + ( this . row - 1 ) * hexagonHeight * 3 / 4 ) ) / 2 ; / / 大 于 一 行 时 为 一 行 的 行 高 + 3 / 2的 行 高
}
this . row = ( Math . round ( this . hexagonData . length / ( this . col * 2 - 1 ) ) + 1 ) * 2
resolve ( ) ;
} )
} ,
@@ -263,45 +328,28 @@
} ) ;
setTimeout ( ( ) => {
this . borderHex ( ) ;
hexagonSvg . zoom ( 0.33 )
getHexagon ( this . hexagonSvgID ) . hexagonSvg . animate ( 300 ) . zoom ( this . defaultRate )
} )
} ,
renderHexagon ( item ) { / / 绘 画 六 边 形
hexagonPoint ( item . left , item . top , this . hexagonEdge ) . then ( data => {
let color = item . level === 'P1' ? '#FAAFAF' : ( item . level === 'P2' ? '#FFCF92' : '#99D7C2' ) ;
let gru op = hexagonSvg . group ( ) ;
let polygon = gru op . polygon ( data . svgStrPoint ) . fill ( color ) ;
/ / l e t p o l y g o n = g r u o p . p o l y g o n ( d a t a . s v g S t r P o i n t ) . a t t r ( ' c l a s s ' , i t e m . l e v e l + ' h e x a g o n _ c h i l d _ c h i l d ' ) . a t t r ( ' s t y l e ' , ' f i l l : l i m e ; s t r o k e : p u r p l e ; s t r o k e - w i d t h : 1 ' ) ;
let color = this . colorSet ? this . colorSet ( item ) : this . defaultColor ;
let grou p = getHexagon ( this . hexagonSvgID ) . hexagonSvg. group ( ) ;
let polygon = grou p . polygon ( data . svgStrPoint ) . fill ( color . color );
polygon . data ( {
... data ,
... item
... item ,
... color
} ) ;
gru op . on ( 'mouseenter' , hexagonEnter ) ;
gru op . on ( 'mouseleave' , hexagonLeave ) ;
gru op . on ( 'click' , this . hexagonSvgScale . bind ( this , polygon . data ( 'center' ) , item , data ) ) ;
grou p . on ( 'mouseenter' , hexagonEnter ) ;
grou p . on ( 'mouseleave' , hexagonLeave ) ;
grou p . on ( 'click' , this . hexagonSvgScale . bind ( this , polygon . data ( 'center' ) , item , data ) ) ;
this . allHexagon . push ( polygon ) ;
this . allGroup . push ( gru op )
this . allGroup . push ( grou p ) ;
/ / 向 六 边 形 内 添 加 文 本 本 质 是 根 据 六 边 形 的 中 心 点 确 定 各 个 文 本 位 置
let rgbColor = '0,0,0' ;
let rect1 = gru op . rect ( this . hexagonEdge , this . hexagonEdge / 3 )
. attr ( {
x : data . center [ 0 ] - this . hexagonEdge / 2 ,
y : data . center [ 1 ] - this . hexagonEdge / 2
} ) . fill ( { color : ` rgba( ${ rgbColor } ,0) ` } ) . data ( { level : item . level , color : rgbColor } ) ;
gruop . text ( )
allHexagonText . push ( rect1 ) ;
let rect2 = gruop . rect ( this . hexagonEdge , this . hexagonEdge / 3
) . attr ( {
x : data . center [ 0 ] - this . hexagonEdge / 2 ,
y : data . center [ 1 ] - this . hexagonEdge / 2 + this . hexagonEdge / 3 + 5
} ) . fill ( { color : ` rgba( ${ rgbColor } ,0) ` } ) . data ( { level : item . level , color : rgbColor } ) ;
allHexagonText . push ( rect2 ) ;
let rect3 = gruop . rect ( this . hexagonEdge , this . hexagonEdge / 3 )
. attr ( {
x : data . center [ 0 ] - this . hexagonEdge / 2 ,
y : data . center [ 1 ] - this . hexagonEdge / 2 + this . hexagonEdge / 3 * 2 + 10
} ) . fill ( { color : ` rgba( ${ rgbColor } ,0) ` } ) . data ( { level : item . level , color : rgbColor } ) ;
allHexagonText . push ( rect3 ) ;
if ( this . infoSet ) {
this . infoSet ( grou p , getHexagon ( this . hexagonSvgID ) . allHexagonRect , getHexagon ( this . hexagonSvgID ) . allHexagonText , data , item , this ) ;
}
} ) ;
@@ -310,20 +358,19 @@
} ,
hexagonSvgScale ( center , item1 , data , e ) {
window . event ? window . event . cancelBubble = true : e . stopPropagation ( ) ;
if ( ! this . pan ) {
hexagonSvg . animate ( 300 ) . zoom ( 1 , { x : center [ 0 ] , y : center [ 1 ] } ) ;
allHexagonText . forEach ( item => {
let rgbColor = item . data ( 'color' )
item . fill ( { color : ` rgba( ${ rgbColor } ,0.05) ` } )
} )
if ( ! this . pan && this . isClickRate ) {
getHexagon ( this . hexagonSvgID ) . hexagonSvg. animate ( 300 ) . zoom ( this . magnifyRate , { x : center [ 0 ] , y : center [ 1 ] } ) ;
if ( this . infoShow ) {
this . infoShow ( getHexagon ( this . hexagonSvgID ) . allHexagonRect , getHexagon ( this . hexagonSvgID ) . allHexagonText )
}
}
} ,
hexagonSvgClearScale ( ) {
if ( ! this . pan ) {
hexagonSvg . animate ( 300 ) . zoom ( 0.33 ) ;
allHexagonText . forEach ( item => {
item . fill ( { color : 'rgba(115,205,175,0)' } )
} )
if ( ! this . pan && this . isClickRate ) {
getHexagon ( this . hexagonSvgID ) . hexagonSvg. animate ( 300 ) . zoom ( this . defaultRate ) ;
if ( this . infoHide ) {
this . infoHide ( getHexagon ( this . hexagonSvgID ) . allHexagonRect , getHexagon ( this . hexagonSvgID ) . allHexagonText )
}
}
} ,
hexColorToRgb ( color ) {
@@ -350,18 +397,21 @@
} ,
hexagonSvgPanStart ( ev ) { / / 实 例 移 动 开 始 解 绑 点 击 函 数
ev . preventDefault ( ) ;
setTimeout ( ( ) => {
setTimeout ( ( ) => { / / 设 置 延 时 解 决 移 动 后 的 缩 放 问 题
this . pan = true ;
} , 100 )
} ,
hexagonSvgPanEnd ( ev ) { / / 实 例 移 动 结 束 重 新 绑 定 点 击 函 数
ev . preventDefault ( ) ;
setTimeout ( ( ) => {
setTimeout ( ( ) => { / / 设 置 延 时 解 决 移 动 后 的 缩 放 问 题
this . pan = false ;
} , 100 )
} ,
borderHex ( ) { / / 外 层 边 框 数 组 点
let length = this . allHexagon . length ;
if ( length == 0 ) { / / 为 0 调 出
return
}
let k = { x : - this . interspace , y : - ( this . interspace * 2 ) * this . MathSqrt3 / 6 } ; / / 边 框 对 起 点 的 偏 移 量
let item = this . allHexagon [ 0 ] . data ( 'point' ) [ 0 ] ;
let endItemSub = this . allHexagon [ length - 1 ] . data ( 'sub' ) . split ( '-' ) ;
@@ -369,7 +419,7 @@
let borderRow = endItemSub [ 0 ] ;
let borderPoint = [ item . x + k . x , item . y + k . y ] ;
let borderSize = this . hexagonEdge * 1.2 ;
svgPolyline = hexagonSvg . polyline ( borderPoint [ 0 ] + ',' + borderPoint [ 1 ] ) . fill ( 'none' ) . stroke ( { color : '#DADADA' , width : 1 , linecap : 'round' , linejoin : 'round' } ) ; / / 边 框 起 点
getHexagon ( this . hexagonSvgID ) . svgPolyline = getHexagon ( this . hexagonSvgID ) . hexagonSvg . polyline ( borderPoint [ 0 ] + ',' + borderPoint [ 1 ] ) . fill ( 'none' ) . stroke ( { color : '#DADADA' , width : 3 , linecap : 'round' , linejoin : 'round' } ) ; / / 边 框 起 点
/ / 先 从 左 到 右 划 线 应 该 是 c o l 的 长 度
let borderColTop = 0 ;
if ( borderRow == 0 ) {
@@ -382,9 +432,9 @@
borderSize = this . hexagonEdge * 1.1
}
if ( i % 2 === 0 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
borderSize = this . hexagonEdge * 1.2
@@ -395,22 +445,22 @@
borderRowRight = 3 ;
for ( let i = 0 ; i < borderRowRight-1 ; i + + ) {
if ( i === 1 ) {
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , t r u e ) ;
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , , g e t H e x a g o n ( t h i s . h e x a g o n S v g I D ) . s v g P o l y l i n e tr u e ) ;
borderSize = this . hexagonEdge * 1.2
}
if ( i === 2 ) {
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , t r u e ) ;
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , , g e t H e x a g o n ( t h i s . h e x a g o n S v g I D ) . s v g P o l y l i n e tr u e ) ;
borderSize = this . hexagonEdge * 1.1
}
if ( i % 4 === 0 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
}
@@ -423,20 +473,20 @@
if ( i == 0 ) {
borderSize = this . hexagonEdge * 1.2 ;
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.2 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.03 ;
if ( i === borderRowRight - 1 ) {
borderSize = this . hexagonEdge * 1.1 ;
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
}
@@ -449,17 +499,17 @@
if ( i == 0 ) {
borderSize = this . hexagonEdge * 1.2
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.2 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.03 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
}
@@ -472,20 +522,20 @@
if ( i == 0 ) {
borderSize = this . hexagonEdge * 1.2
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.2 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.03 ;
if ( i === borderRowRight - 1 ) {
borderSize = this . hexagonEdge * 1.1 ;
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
} / / 向 下 移 动
borderSize = this . hexagonEdge * 1.2
@@ -497,13 +547,13 @@
borderSize = this . hexagonEdge
}
if ( i % 2 === 0 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
borderSize = this . hexagonEdge * 1.1
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
/ / 情 况 5 b o r d e r C o l < t h i s . c o l & & r o w > 0 且 r o w 为 偶 数 事
if ( borderCol < this .col -1 & & borderRow > 0 && borderRow % 2 == 0 ) {
@@ -514,20 +564,20 @@
if ( i == 0 ) {
borderSize = this . hexagonEdge * 1.2
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 2 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.2 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.03 ;
if ( i === borderRowRight - 2 ) {
borderSize = this . hexagonEdge * 1.15 ;
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
borderSize = this . hexagonEdge * 1.2
@@ -542,28 +592,28 @@
borderSize = this . hexagonEdge * 1.1
}
if ( i % 2 === 0 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
borderSize = this . hexagonEdge * 1.1
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 3 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
/ / 从 右 到 左 就 是 结 束 时 的 列 数
borderSize = this . hexagonEdge * 1.2
for ( let i = 0 ; i <= borderCol * 2 + 1 ; i ++ ) {
if ( i === 1 ) {
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , t r u e ) ;
/ / b o r d e r P o i n t = b o r d e r M o v e ( b o r d e r P o i n t [ 0 ] , b o r d e r P o i n t [ 1 ] , b o r d e r S i z e , 2 , , g e t H e x a g o n ( t h i s . h e x a g o n S v g I D ) . s v g P o l y l i n e tr u e ) ;
borderSize = this . hexagonEdge * 1.1
}
if ( i == borderCol * 2 + 1 ) {
borderSize = this . hexagonEdge * 1.2
}
if ( i % 2 === 0 ) {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 4 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else {
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
/ / 从 下 向 上 的 移 动
@@ -576,17 +626,17 @@
if ( i !== 0 ) {
borderSize = this . hexagonEdge * 1.03 ;
}
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.2 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
}
@@ -594,42 +644,47 @@
for ( let i = 0 ; i <= borderRow * 2 ; i ++ ) {
if ( i % 4 === 0 ) {
borderSize = this . hexagonEdge * 1.2
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 1 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 1 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
else if ( i % 4 === 2 ) {
borderSize = this . hexagonEdge * 1.03 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 6 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
} else if ( i % 4 === 3 ) {
borderSize = this . hexagonEdge * 1.1 ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 ) ;
borderPoint = borderMove ( borderPoint [ 0 ] , borderPoint [ 1 ] , borderSize , 5 , getHexagon ( this . hexagonSvgID ) . svgPolyline );
}
}
}
} ,
clearData ( ) { / / 清 除 数 据 以 及 解 绑 事 件 防 止 内 存 崩 溃
if ( hexagonSvg ) {
if ( getHexagon ( this . hexagonSvgID ) && getHexagon ( this . hexagonSvgID ) . hexagonSvg) {
this . allHexagon . forEach ( ( item ) => {
item . off ( 'mouseenter' , hexagonEnter ) ;
item . off ( 'mouseleave' , hexagonLeave ) ;
item . off ( 'click' , this . hexagonSvgScale ) ;
/ / i t e m .c l e a r ( ) ;
ite m .clea r ( ) ;
} )
this . allHexagon = [ ] ;
this . hexagonData = [ ] ;
hexagonSvg . off ( 'click' , this . hexagonSvgClearScale ) ;
/ / s v g P o l y l i n e . c l e a r ( ) ;
/ / h e x a g o n S v g .c l e a r ( ) ;
hexagonSvg = null ; / / S v g 的 实 例
svgPolyline = null / / S v g h e x a g o n 的 边 框
getHexagon ( this . hexagonSvgID ) . hexagonSvg. off ( 'click' , this . hexagonSvgClearScale ) ;
getHexagon ( this . hexagonSvgID ) . hexagonSvg . off ( 'panStart' , this . hexagonSvgPanStart ) ;
getHexagon ( this . hexagonSvgID ) . hexagonSv g .off ( 'panEnd' , this . hexagonSvgPanEnd ) ;
getHexagon ( this . hexagonSvgID ) . hexagonSvg= null ; / / S v g 的 实 例
getHexagon ( this . hexagonSvgID ) . svgPolyline= null ; // S v g h e x a g o n 的 边 框
delHexagon ( this . hexagonSvgID )
}
} ,
} ,
beforeDestroy ( ) {
this . clearData ( )
this . clearData ( ) ;
if ( getHexagon ( this . hexagonSvgID ) ) {
getHexagon ( this . hexagonSvgID ) . allHexagonRect = null ; / / 文 本 框
getHexagon ( this . hexagonSvgID ) . allHexagonText = null ; / / 文 本 内 容
}
}
}
< / script >