import { Params } from '@antv/g2plot' ; import { QRCodeOptions } from './types' ; import { qr } from './qrcode' ; param options export const defaultOptions = { data : 'Hello, g2plot qrcode!' , backgroundColor : 'white' , foregroundColor : 'black' , typeNumber : 0 , correctLevel : 'H' , padding : 8 , width : 120 , height : 120 , autoFit : false , } ; param params export function adaptor ( params ) { const { chart , options } = params ; const { width , height , data , correctLevel , typeNumber , foregroundColor , backgroundColor , pixelStyle , icon } = options ; const dataArr = qr ( data , correctLevel , typeNumber ) ; chart . data ( dataArr ) ; chart . scale ( { i : { type : 'cat' , } , j : { type : 'cat' , } , } ) ; chart . polygon ( ) . position ( 'i*j' ) . color ( 'isForeground' , ( v ) => { return v ? foregroundColor : backgroundColor ; } ) . style ( 'i*j*isForeground*isBackground*detection*detectionPosition' , ( i , j , isForeground , isBackground , detection , detectionPosition ) => { return typeof pixelStyle === 'function' ? pixelStyle ( { i , j , isForeground , isBackground , detection , detectionPosition } ) : { } ; } ) ; if ( icon ) { const { image , width : imageWdith = 32 , height : imageHeight = 32 } = icon ; if ( image ) { chart . annotation ( ) . shape ( { render : ( container ) => { container . addShape ( 'image' , { attrs : { x : ( width - imageWdith ) / 2 , y : ( height - imageHeight ) / 2 , width : imageWdith , height : imageHeight , img : image , } , } ) ; } , } ) ; } } chart . coordinate ( ) . reflect ( 'y' ) ; chart . axis ( false ) ; chart . legend ( false ) ; chart . tooltip ( false ) ; chart . animate ( false ) ; return params ; }