How to use the snapsvg.cos function in snapsvg

To help you get started, we’ve selected a few snapsvg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fralonra / lottery-wheel / src / index.js View on Github external
fill: d.color ? d.color : opt.color.prize,
        stroke: opt.color.line,
        strokeWidth: 2
      })

      let fontSize = d.fontSize ? d.fontSize : (opt.fontSize ? opt.fontSize : baseFontSize)
      let textSum = 0 // a-z0-9 为 1,其他为 2
      for (let i = 0; i < d.text.length; ++i) {
        if (d.text[i].match(/\w/)) {
          textSum += 1
        } else textSum += 2
      }
      if (!opt.fontSize && !d.fontSize) {
        fontSize = fontSize * textSum / 2 > dLen * opt.textBottomPercentage ? dLen * opt.textBottomPercentage / textSum * 2 : fontSize
      }
      const text = svg.text(opt.center[0], opt.pos[1] + opt.radius - (r * opt.textBottomPercentage * Snap.cos(self[deg] / 2)) - fontSize, d.text)
      text.attr({
        fill: d.fontColor ? d.fontColor : opt.color.prizeFont,
        fontSize: opt.fontSize ? opt.fontSize : fontSize
      })
      const box = text.node.getBoundingClientRect()
      text.transform(new Snap.Matrix().translate(-Math.round(box.width / 2), 2))

      const g = svg.g(pie, text).transform(new Snap.Matrix().rotate(self[deg] * Number(i), opt.center[0], opt.center[1]))
      self[turntable].add(g)
    }
  }
github fralonra / lottery-wheel / src / index.js View on Github external
[drawButton] (svg) {
    const self = this
    if (self[button]) return

    const opt = self.option

    if (opt.button && typeof opt.button === 'string') {
      return
    }

    const r = opt.buttonWidth / 2
    const center = opt.center
    const deg = (180 - opt.buttonDeg) / 2
    const [pathArc, , , end] = describeArc(center[0], center[1], r, deg - 360, 360 - deg)
    const top = [center[0], center[1] - r / Snap.cos(deg)]
    const pathD = `${pathArc}L${top[0]},${top[1]}L${end.x},${end.y}L${center[0]},${center[1]}`
    const b = svg.path(pathD)
    b.attr({
      fill: opt.color.button,
      filter: svg.filter(Snap.filter.shadow(0, 3, 3, 'black', 0.5))
    })

    let text = null
    if (opt.buttonText !== '') {
      const maxLen = r * 2 * 0.8
      let fontSize = opt.buttonFontSize ? opt.buttonFontSize : baseFontSize
      let textSum = 0
      for (let i = 0; i < opt.buttonText.length; ++i) {
        if (opt.buttonText[i].match(/\w/)) {
          textSum += 1
        } else textSum += 2

snapsvg

JavaScript Vector Library

Apache-2.0
Latest version published 7 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages