1.0.1 • Published 6 months ago

scale-ruler-vue3 v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

scale-ruler-vue3

A vue3 public component, an excellent assistant for building a low-code platform. It supports free movement and scaling of the canvas within the area, and includes ruler, positioning line and adsorption line functions.

中文

demo

Features

  • vue3 components API
  • Support typescript
  • Supports shortcut key zoom(e.g. use ctrl + '+' and ctrl + '-' to zoom) , mouse zoom and touchpad dual finger pinch zoom
  • Supports free movement and scroll bar movement
  • Easy and fast access

Installation

Using Package Manager

npm install scale-ruler-vue3 --save
or
yarn add scale-ruler-vue3
# or
pnpm add scale-ruler-vue3
# or
bun add scale-ruler-vue3

Import in Browser

unpkg

<head>
  <!-- Import style -->
  <link rel="stylesheet" href="//unpkg.com/scale-ruler-vue3/lib/index.css" />
  <!-- Import Vue 3 -->
  <script src="//unpkg.com/vue@3"></script>
  <!-- Import component library -->
  <script src="//unpkg.com/scale-ruler-vue3"></script>
</head>

jsDelivr

<head>
  <!-- Import style -->
  <link
    rel="stylesheet"
    href="//cdn.jsdelivr.net/npm/scale-ruler-vue3/lib/index.css"
  />
  <!-- Import Vue 3 -->
  <script src="//cdn.jsdelivr.net/npm/vue@3"></script>
  <!-- Import component library -->
  <script src="//cdn.jsdelivr.net/npm/scale-ruler-vue3"></script>
</head>

Quick Start

<template>
  <ScaleRuler
    ref="scaleRulerRef"
    v-model:scale="opt.scale"
    :auto-scale="opt.autoScale"
    :canvas-width="opt.canvasWidth"
    :canvas-height="opt.canvasHeight"
    :container-auto-size="true"
    :canvas-style="opt.canvasStyle"
  ></ScaleRuler>
</template>

<script setup>
import {reactive} from 'vue';
import ScaleRuler from 'scale-ruler-vue3';
const opt = reactive({
  canvasWidth: 1920,
  canvasHeight: 1000,
  autoScale: true,
  scale: 1,
  canvasStyle: {
    backgroundColor: '#ccc'
  }
});
</script>

Reference code

Attributes

AttributeDescriptionTypeDefaultRemark
scale/v-model:modelScale ratio of canvasNumber1If autoScale is true,The initial value of scale does not take effect
minScaleThe minimum value of scale ratio of canvasNumber0.1
maxScaleThe maximum value of scale ratio of canvasNumber10
autoScaleWhether to automatically calculate the scale ratio of canvas during initializationBooleantrue
canScaleWhether scaling is allowed or notBooleantrue
autoCenterWhether to automatically center the canvas during initializationBooleantrue
containerAutoSizeWhether to automatically calculate the width and height of the containerBooleantrueIf true, it will monitor the changes of container width and height and repaint the canvas and ruler
containerWidthContainer widthNumber1000If containerAutoSize is true, this value does not take effect
containerHeightContainer heightNumber500If containerAutoSize is true, this value does not take effect
containerXPaddingThe left and right padding between the container and the canvas in the x-direction/horizontal directionNumber800
containerYPaddingThe top and bottom padding between the container and the canvas in the y-direction/vertical directionNumber800
canvasWidthCanvas widthNumber1920
canvasHeightCanvas heightNumber1000
canvasStyleThe style of canvasObject{}
proxyScaleKeyWhether to proxy the shortcut key zoom function or notBooleantrueproxy ctrl+ "+" to zoom in and ctrl + "-" to zoom out
useScrollBarWhether to use scrollbarBooleantrue
scrollBarConfigThe config of scrollbarObject{}see scrollBarConfig params
useRulerWhether to use rulerBooleantrue
rulerConfigThe config of rulerObject{}see rulerConfig params
usePositionLineWhether to use position lineBooleantrue
positionLineConfigThe config of position lineObject{}see positionLineConfig params

scrollBarConfig params

AttributeDescriptionTypeDefaultRemark
bgColorbackground colorString#000000
opacityopacityNumber0.4
zIndexzIndexNumber500
sizeThe height of horizontal scrollbar and the width of vertical scrollbarNumber8

rulerConfig params

AttributeDescriptionTypeDefaultRemark
xRulerHeightThe height of x/horizontal rulerNumber30Do not bigger than the containerYPadding
yRulerWidthThe width of y/vertical rulerNumber30Do not bigger than containerXPadding
bgColorBackground color of rulerString#efefef
fontColorThe color of number in rulerString#000000
fontSizeThe font size of number in rulerNumber12
fontFamilyThe font family of number in rulerStringArial
lineColorThe line color of rulerString#000000
zIndexzIndexNumber400

positionLineConfig params

AttributeDescriptionTypeDefaultRemark
lineColorThe color of position lineString#24aa61
paddingThe padding of operationNumber3
adsorptionXListThe list of adsorption in x/horizontal directionArray0, canvasWidth
adsorptionYListThe list of adsorption in y/vertical directionArray0, canvasHeight
adsorptionGapThe gap to adsorbNumber4
zIndexzIndexNumber300
useRightKeyRemoveWhether to enable right key delete the position linebooleantrue
removeIconThe component of remove-iconComponentIf useRightKeyRemove is true, the value of removeIcon will effective;If removeIconis empty, the default component of icon will effective
removeIconFillColorThe fill-color of remove-iconstring#525252

Events

Methods NameDescriptionParameters
onScaletriggers when scaling the canvasscale: number
onMovetriggers when moving the canvastranslateX: number, translateY: number
adsorptionLineChangetriggers when adsorption line(s) change(s)value: number[], isY: boolean
positionLineChangetriggers when position line(s) change(s)value: number[], isY: boolean

Methods

Methods NameDescriptionParameters
resetreset the canvas-
changeScalechange the scale ratio of canvas(scale:number)
removeAllPositionLineremove all the position line(s)-
showRulershow rulers-
hideRulerhide rulers-
showAllPositionLineshow all the position line(s)-
hideAllPositionLinehide all the position line(s)-
addAdsorptionLineadd adsorption line(s)(data: number | Array- the value of adsorption line, isY: boolean -Whether it is in the y/vertical direction)
removeAdsorptionLineremove adsorption line(s)(data: number | Array- the value of adsorption line, isY: boolean -Whether it is in the y/vertical direction)
1.0.1

6 months ago

1.0.0

6 months ago