/* -------------------------- */ /* solarsPlugin */ /* -------------------------- */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory((global.solarsPlugin = global.solarsPlugin || {}))); }(this, function (exports) { 'use strict'; var solarsPlugin = function solarsPlugin(__mapper = {}) { let config = {} config.width = 600 config.height = 400 config.startX = 100 config.startY = 125 config.step = 50 config.rotrx = 40 // x rotation radius config.rotry = 20 // y rotation radius let solar = {} solar.count = 1 solar.arms = 4 solar.LineWidth = 1 solar.stroke = "red" solar.opacity = 0.9 solar.fill = "red" solar.firstX = 300 solar.firstY = 100 solar.colSep = 50 solar.rowSep = 30 solar.radius = 3 solar.cols = 8 solar.pos = function pos(idx, p0, c, cols) { var r = c.cw / 2 // radius or col width / 2 var row = (idx / cols) >> 0 // i in matrix: row per index var col = idx % cols // j in matrix: column per index var px = 300 // Math.random() * config.width // p0.x + c.cw * col + r // abs x: x0 + col * cw + r var py = 175 // Math.random() * config.height // p0.y + c.ch * row + r // abs x: x0 + col * cw + r var p = {x: px, y: py, rad: r, id: idx} return p } solar.GenX = (i) => solar.pos(i, {x: solar.firstX, y: solar.firstY}, {cw: solar.colSep, ch: solar.rowSep}, solar.cols).x solar.GenY = (i) => solar.pos(i, {x: solar.firstX, y: solar.firstY}, {cw: solar.colSep, ch: solar.rowSep}, solar.cols).y solar.items = d3.range(solar.count).map(function(d, i) { var randomAngle = Math.random() * 2 * Math.PI var formparams = { "m1":4.718177045786351,"m2":19.396126213759022,"n1":15.313427387158098,"n2":10.738988564746812,"n3":15.119538381452617,"b":7.059625076609466,"a":-13.981619631491435, "tx":300, "ty":200, "rot":0, "rad":45, "segs":720, "pta": 0, "ptb": -1, "v0":0,"v1":1, "cf":522,"cs":422, "kx":1, "ky":1, } var vx = 0 // 5 * Math.cos(randomAngle) // 0 // browninan movement var vy = 0 // 5 * Math.cos(randomAngle) // 0 // as per Robert Monfera return { radius: formparams.rad, arms: solar.arms, x: solar.GenX(i), y: solar.GenY(i), vx: vx, vy: vy, pslinks: [], // ref to raptors type: 'solar', color: solar.fill, idx: i, id: i, key: i, energy: solar.count - i, links: [], points: [], path: "", formparams: formparams } }) var solarsPlugin = function solarsPlugin() {} solarsPlugin.items = function items(_) { return solar.items } solarsPlugin.render = function render(_) { var color = d3.interpolatePlasma // __mapper({'config': configDotsPlugin.configDotsPlugin()}) __mapper({'xsf': xsfPlugin.xsfPlugin(__mapper)}) var itemsIds = (d, i) => d.idx var solarItems = __mapper("solars").items() solarItems = solarItems.map(function(d, i) { let p = Object.assign(d.formparams, { "tx":d.x, "ty":d.y }) let points = __mapper('xsf')(p).tfpoints() d.points = points return d }) solarItems = solarItems.map(function(d, i) { let path = d3.line()(d.points) d.path = path return d }) // console.log("solarItems", solarItems) var solarsLayer = __mapper("svg")({cls: 'solars', item: 'path.solarPath', data: solarItems, idfn: itemsIds}) solarsLayer.m .attr("d", function(d) { // let p = Object.assign(d.formparams, { // "tx":d.x, // "ty":d.y // }) // let pts = (__mapper('xsf')(p).tfpoints()) // return d3.line()(pts) return d.path }) .style("fill", function (d) { var r = 0 var w = config.width / 2 var h = config.height / 2 r = color(1 - ((Math.abs(w - d.x) / w) + (Math.abs(h - d.y) / h)) / 20) r = solar.fill return r }) .style("fill-opacity", solar.opacity) .style("stroke", solar.stroke) .style("stroke-width", solar.LineWidth) solarsLayer.x .remove() } return solarsPlugin } exports.solarsPlugin = solarsPlugin }));