This commit is contained in:
djerom
2022-04-22 18:34:31 +05:00
commit 813abcd9d4
24 changed files with 1228 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
const SvgNodes = require("./svg-nodes");
module.exports = (name) => SvgNodes.group(['<metadata id="CorelCorpID_WWPTCorel-Layer"/>']).set_attr("id", name);

134
svgmap/drawers/svg-nodes.js Normal file
View File

@@ -0,0 +1,134 @@
const SvgNode = require("./../svg-node.js");
function svg() {
return new SvgNode("svg", {
version: "1.1",
xmlns: "http://www.w3.org/2000/svg",
"xml:space": "preserve",
"xmlns:xlink": "http://www.w3.org/1999/xlink",
style: "shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd",
// viewBox: "0 0 2000 2000"
});
}
function node(name, attrs, items) {
return new SvgNode(name, attrs, items);
}
function container(items) {
return new SvgNode(null, null, items);
}
function group(items) {
return new SvgNode("g", null, items);
}
function circle(r) {
return new SvgNode("circle", { r });
}
function ngon(r, n, ang = 0) {
const da = (2 * Math.PI) / n;
ang = (ang * Math.PI) / 180;
const pts = Array(n)
.fill(0)
.map((x, i) => [Math.sin(i * da + ang) * r, Math.cos(i * da + ang) * r]);
return new SvgNode("polygon", { points: pts.map((x) => `${x[0]},${x[1]}`) });
}
function spike1(w, h, ang) {
const da = (ang * Math.PI) / 180;
const sa = Math.sin(da);
const ca = Math.cos(da);
h = h / 2;
const pts = `${-sa * h},${-ca * h} ${ca * w},${-sa * w}, ${sa * h},${ca * h}`;
return new SvgNode("polygon", { points: pts });
}
function sector(r, a0, a1) {
const k = Math.PI / 180;
let s0 = -Math.sin(a0 * k) * r;
let c0 = Math.cos(a0 * k) * r;
let s1 = -Math.sin(a1 * k) * r;
let c1 = Math.cos(a1 * k) * r;
var aa = a1 - a0 > 180 ? 1 : 0;
// var p = new TimalSvg.Data.SvgPath(string.Format("M0 0 L{0} 0 A {0} {0} 0 {3} 0 {1} {2} z", FN(r), ca, sa, aa));
// p.Transform = string.Format("rotate({0})", FN(ang / 2));
return new SvgNode("path", { d: `M0 0 L${c0} ${s0} A ${r} ${r} 0 ${aa} 0 ${c1} ${s1} z` });
}
function ring_sector(r0, r1, a0, a1) {
const k = Math.PI / 180;
let s0 = -Math.sin(a0 * k);
let c0 = Math.cos(a0 * k);
let s1 = -Math.sin(a1 * k);
let c1 = Math.cos(a1 * k);
var aa = a1 - a0 > 180 ? 1 : 0;
return new SvgNode("path", {
d: `M${c0 * r0} ${s0 * r0}
A ${r0} ${r0} 0 ${aa} 0 ${c1 * r0} ${s1 * r0}
L${c1 * r1} ${s1 * r1}
A ${r1} ${r1} 0 ${aa} 1 ${c0 * r1} ${s0 * r1} z`,
});
}
/**
*
* @param r0
* @param r1
* @param a0
* @param a1
* @param { [{v, style}] } rings
*/
function ring_sectors(r0, r1, sectors) {
let sum = sectors.reduce((s, c) => s + c.v, 0);
let angs = sectors.reduce((s, c, i) => [...s, { ...c, a0: i && s[i - 1].a1, a1: c.v + (i && s[i - 1].a1) }], []);
let items = angs.map((x) => ring_sector(r0, r1, (x.a0 * 360) / sum, (x.a1 * 360) / sum).add_style(x.style));
return group(items);
}
function text(text) {
let node = new SvgNode("text");
node.items = [text];
node.set_attrs({ x: 0, y: 0 });
return node;
}
const defs = {
simple: {
radialGradient(id, color0, color1) {
let s0 = new SvgNode("stop", { offset: "0%", "stop-color": color0 });
let s1 = new SvgNode("stop", { offset: "100%", "stop-color": color1 });
return new SvgNode("radialGradient", { id }).append(s0, s1);
},
},
radialGradient(id, cx, cy, r) {
return new SvgNode("radialGradient", { id, cx, cy, r });
},
stop(offset, color) {
return new SvgNode("stop", { offset, "stop-color": color });
},
};
module.exports = {
node,
svg,
container,
group,
circle,
ngon,
spike1,
sector,
ring_sector,
ring_sectors,
text,
};
module.exports.default = module.exports;

View File

@@ -0,0 +1,30 @@
// export default {
// wellhead: {
// prod(x, y, r, style){
// return SvgNodes.circle(r).add_style(style).move(w.x, w.y);
// },
// inj(x, y, r, style){
// return SvgNodes.circle(r).add_style(style).move(w.x, w.y);
// }
// },
// // [{x,y}]
// heads(wells, r, style) {
// return wells.map((w) => SvgNodes.circle(r).add_style(style).move(w.x, w.y));
// },
// // [{x,y,name}]
// names(wells, style, shift) {
// return wells.map((w) =>
// SvgNodes.text(w.name)
// .add_style(style)
// .move(w.x + shift.x, w.y + shift.y)
// );
// },
// // {x,y,ring[1,2,3,4,5]}
// ring(x, y, r0, r1, a0, a1, style) {
// return SvgNodes.ring_sector(r0, r1, a0, a1).move(x, y).add_style(style);
// },
// }

View File

@@ -0,0 +1,77 @@
const SvgNode = require("./../svg-node.js");
const SvgNodes = require("./svg-nodes.js");
function name(text, ppu, styles) {
return SvgNodes.text(text)
.move(styles["wellhead-name"].dx * ppu, styles["wellhead-name"].dy * ppu)
.add_style(styles["wellhead-name"]);
}
function wlp(wlf, ppu, styles) {
return SvgNodes.text(`${Math.round(wlf * 1000) / 10 || ""}%`)
.move(styles.wlf.dx * ppu, styles.wlf.dy * ppu)
.add_style(styles.wlf);
}
/**
* Добывающая скважина
* @param {*} ppu
* @param {*} styles
* @returns
*/
function prod(ppu, styles) {
return SvgNodes.circle(1.5 * ppu).add_style(styles["wellhead-black"]);
}
/**
* Нагнетательная
* @param {*} ppu
* @param {*} styles
* @returns
*/
function inj(ppu, styles) {
const style_spike = {
"stroke-width": "0",
fill: "#000",
};
const style_blue = {
"stroke-width": Math.round(styles._units["1pt"]),
stroke: "#000",
fill: "#00f",
};
return SvgNodes.group([
SvgNodes.group([
SvgNodes.spike1(1.8 * ppu, 1.7 * ppu, 0).move(2 * ppu, 0),
SvgNodes.spike1(1.8 * ppu, 1.7 * ppu, 90).move(0, -2 * ppu),
SvgNodes.spike1(1.8 * ppu, 1.7 * ppu, 180).move(-2 * ppu, 0),
SvgNodes.spike1(1.8 * ppu, 1.7 * ppu, 270).move(0, 2 * ppu),
]).add_style(style_spike),
new SvgNode("line", { x1: -2 * ppu, x2: 2 * ppu, y1: 0, y2: 0 }),
new SvgNode("line", { y1: -2 * ppu, y2: 2 * ppu, x1: 0, x2: 0 }),
SvgNodes.circle(1.5 * ppu).add_style(style_blue),
]).add_style(style_blue);
}
/**
* Серая с треугольником с малым дебитом/нагнетанием
* @param {*} ppu
* @param {*} styles
* @returns
*/
function gray(ppu, styles) {
return SvgNodes.group([
SvgNodes.circle(1.5 * ppu).add_style(styles["wellhead-gray"]),
SvgNodes.ngon(1.5 * ppu, 3, 0).add_style(styles["wellhead-black"]),
]);
}
module.exports = {
name,
wlp,
prod,
inj,
gray
};
module.exports.default = module.exports;

View File

@@ -0,0 +1,18 @@
const SvgNodes = require("./svg-nodes");
function pt(wopt, wwpt, rmm, ppu, style) {
return SvgNodes.ring_sectors(1.5 * ppu, rmm * ppu, [
{ v: wopt, style: style.opt },
{ v: wwpt, style: style.wpt },
]);
}
function it(rmm, ppu, style) {
return SvgNodes.circle(rmm * ppu).add_style(style.wit);
}
module.exports = {
pt,
it,
};
module.exports.default = module.exports;