New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wafer-map

Package Overview
Dependencies
Maintainers
0
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wafer-map

SVG Map for react

  • 3.0.83
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by133.33%
Maintainers
0
Weekly downloads
 
Created
Source

English | 简体中文

wafer-map

SVG Map for react

Using

  • install

npm i wafer-map yarn add wafer-map

  • using in react
import React, { Component } from 'react';
import WaferMap from 'wafer-map';

class App extends Component {
     render() {
         const mapProps = {
             mapId: '1',
             componentWidth: 1920,
             componentHeight: 1080
         };
 
         return (
             <div className="App">
                 <WaferMap {...mapProps}/>
             </div>
         );
     }
}

notice: mapId is the only mark on the map.

Props

Propdefault valueis requireddescription
mapIdtruemap id
componentWidth1920falseMap the width of containers
componentHeight1080falseMap the height of containers
background#dddfalseMap container background color
visibleElement[]falseDisplayable collection of element ids
visibleType[]falseDisplayable collection of element types
visibleState[]falseDisplayable collection of element states
clickableElement[]falseClickable collection of element ids
clickableType[]falseClickable collection of element types
clickableState[]falseClickable collection of element states
onClickfalseRadio callback method
onSelectfalseMulti-select callback method
onClickErrorfalseSelect the callback method for the exception
mapZoomtruefalseScale the map
mapMovetruefalseMove the map
multiplefalsefalseMultiple switch
noNamefalsefalseElement names are not displayed on the map.
showPathfalsefalseDisplay roadmap
markIdfalseThe element id that needs to be tagged, such as '1'; If multiple, use string array format, such as ['1', '2']
showStateIds[]falseDisplay different states of different elements, data structure:[{id: 1, state: 'XX', color: '#fff', text: ''}, {}]
reloadMapfalseReload the map
reloadFinishfalseReload the map to complete the callback
touchablefalseTouch control
deleteIdfalseDelete selected element id
deleteFinishfalseCallback after deleting selected element
tooltipContentfalseDisplay tooltip
elementsColor[]falseSet color according to element id, data structure:[{id: 1, color: '#fff'}, {}]
pathStartSvgfalseGuide start icon, this icon contains only elements inside svg, without svg tags
pathEndSvgfalseGuide end icon, this icon contains only elements inside svg, without svg tags
pathStylefalseGuide leader style, style setting reference svg element attributes
markSvgfalseSearch anchor or mark icon, this icon contains only elements inside svg, without svg tags
selectedSvgfalseCheck icon, this icon contains only elements inside svg, without svg tags
defaultTooltipKey''You can customize the default key in the bubble, such as orgName
getSvgDom''Get viewerdom of SVG callback method
signatureKeynullfalseSignature key
restfulSignaturefalsefalseControls whether to sign or not, when set to true, the signature key must be set to a valid value
textColor#ffffalseelements text color
scaleFactorMax5falsemaximum amount of scale a user can zoom in to
scaleFactorMin0.5falseminimum amount of scale a user can zoom out of
isGendersfalsefalseDisplay male and female outsourcing type avatars before the name of the material

onClickError Error Code

codedescription
100Selected elements that cannot be displayed
101Selected elements that the ID cannot be selected
102Selected elements that the types cannot be selected
103Selected elements that the states cannot be selected
104Multi-select mode cannot select different types at the same time

function

namepropsreturndescription
reloadElementsReload the elements on the map
clearSelectElementClears the selected set of elements

tooltipContent example of use

tipObj is the object returned by this method

 tooltipContent = (tooltipObj)=>{
    const radius = 5;
    const width = 150;
    const height = 45;
    return (
        <g>
          <path
              fill="black"
              fillOpacity="0.7"
              d={`M0 0 l10 10 h ${width / 2 - 10 - radius}
          a ${radius} ${radius} 90 0 1 ${radius} ${radius} v ${height}
          a ${radius} ${radius} 90 0 1 ${-radius} ${radius} h ${2 * radius - width}
          a ${radius} ${radius} 90 0 1 ${-radius} ${-radius} v ${-height}
          a ${radius} ${radius} 90 0 1 ${radius} ${-radius} h ${width / 2 - 10 - radius} Z`}
          />
          <text
              dy="23"
              dominantBaseline="text-before-edge"
              fill="white"
              textAnchor="middle"
          >
            {tooltipObj.orgName}
          </text>
        </g>
    )
  }

tooltipObj对象需要从 getMapStationList这个方法里获取数据存入contentObj对象,获取完整的对象

 *getMapStationList({ payload }, { call, put, select }) {
      const { locationId } = yield select(state => state.swsCommon);
      const param = payload || { locationId };
      const { info } = yield select(state => state.login);
      if (info && info.tenant_id) {
        param.domainId = info.tenant_id;
      }
      const result = yield call(service.getMapStationList, { payload: param });
      if (result && result.code === 0) {
        const onMapList = [];
        const visibleList = [];
        result.data.forEach(item => {
          if (item && item.elementId) {
            visibleList.push(item.elementId);
            onMapList.push({
              id: item.elementId,
              state: item.statusCode,
              color: item.statusColor,
              text: item.userNames || item.stationNum,
              contentObj: item
            });
          }
        });

        yield put({
          type: 'saveOrUpdateData',
          payload: {
            mapStationList: result.data,
            stationsOnMap: onMapList,
            visibleList,
          },
        });
      }
    }   

Keywords

FAQs

Package last updated on 30 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc