@welldot/render 0.1.0-next.20260509.039db95 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -496,9 +496,6 @@ var DEFAULT_COMPONENTS_CLASS_NAMES = {
496
496
  import textures2 from "textures";
497
497
 
498
498
  // src/utils/d3.utils.ts
499
- function mergeEnter(enter, update) {
500
- return enter.merge(update);
501
- }
502
499
  function withTransition(selection, transition) {
503
500
  return selection.transition(transition);
504
501
  }
@@ -516,6 +513,18 @@ var getYAxisFunctions = (yScale, clamp) => {
516
513
  getYPos: ({ from }) => yScale(Math.max(from, clampFrom))
517
514
  };
518
515
  };
516
+ function hashStr(s) {
517
+ let h = 5381;
518
+ for (let i = 0; i < s.length; i++) {
519
+ h = Math.imul(h, 33) ^ s.charCodeAt(i);
520
+ }
521
+ return (h >>> 0).toString(36);
522
+ }
523
+ function stableLayerKey(d) {
524
+ const { from: _f, to: _t, ...rest } = d;
525
+ const sortedKeys = Object.keys(rest).sort();
526
+ return hashStr(JSON.stringify(rest, sortedKeys));
527
+ }
519
528
  function filterByDepth(depthFrom, depthTo) {
520
529
  return (l) => !(l.to <= depthFrom || l.from >= depthTo);
521
530
  }
@@ -568,10 +577,11 @@ import d3tip from "d3-tip";
568
577
  import sanitizeHtml from "sanitize-html";
569
578
  var d3 = Object.assign(d3module, { tip: d3tip });
570
579
  var esc = (v) => sanitizeHtml(String(v ?? ""), { allowedTags: [], allowedAttributes: {} });
580
+ var _tooltipCache = /* @__PURE__ */ new WeakMap();
571
581
  var populateTooltips = (svg, customClasses, units, tooltipConfig) => {
572
582
  const svgEl = typeof svg.node === "function" ? svg.node() : null;
573
- if (svgEl?.getAttribute("data-tooltips-init") === "true") {
574
- return {};
583
+ if (svgEl && _tooltipCache.has(svgEl)) {
584
+ return _tooltipCache.get(svgEl);
575
585
  }
576
586
  const tipsText = {
577
587
  geology: (_, d) => `
@@ -667,6 +677,7 @@ var populateTooltips = (svg, customClasses, units, tooltipConfig) => {
667
677
  );
668
678
  });
669
679
  svgEl?.setAttribute("data-tooltips-init", "true");
680
+ if (svgEl) _tooltipCache.set(svgEl, tooltips);
670
681
  return tooltips;
671
682
  };
672
683
 
@@ -684,13 +695,20 @@ var preloadFgdcTextures = () => {
684
695
  var getLithologicalFillList = (data, opts) => {
685
696
  const uniqueTextureCodes = [...new Set(data.map((d) => d.fgdc_texture))];
686
697
  const texturesLoaded = Object.fromEntries(
687
- uniqueTextureCodes.filter((code) => _fgdcTextures[code]).map((code) => [code, _fgdcTextures[code]])
698
+ uniqueTextureCodes.filter((code) => {
699
+ const path = _fgdcTextures[code];
700
+ return path && path !== "-" && /^[Mm]/.test(path);
701
+ }).map((code) => [code, _fgdcTextures[code]])
688
702
  );
689
703
  return Object.fromEntries(
690
- data.map((d) => [
691
- `${d.fgdc_texture}.${d.from}`,
692
- textures2.paths().d(() => texturesLoaded[d.fgdc_texture]).size(opts.size).strokeWidth(opts.strokeWidth).stroke(opts.stroke).background(d.color)
693
- ])
704
+ data.map((d) => {
705
+ const pathData = texturesLoaded[d.fgdc_texture];
706
+ if (!pathData) return [`${d.fgdc_texture}.${d.from}`, d.color];
707
+ return [
708
+ `${d.fgdc_texture}.${d.from}`,
709
+ textures2.paths().d(() => pathData).size(opts.size).strokeWidth(opts.strokeWidth).stroke(opts.stroke).background(d.color)
710
+ ];
711
+ })
694
712
  );
695
713
  };
696
714
  var getLithologyFill = (geologyData, svg, opts) => {
@@ -1006,19 +1024,36 @@ function drawConstructive(ctx, data) {
1006
1024
  }).attr("fill", ctx.textures.pad.url()).attr("stroke", ctx.theme.cementPad.stroke).attr("stroke-width", ctx.theme.cementPad.strokeWidth);
1007
1025
  newCementPad.on("mouseover", ctx.tooltips.cementPad.show).on("mouseout", ctx.tooltips.cementPad.hide);
1008
1026
  }
1009
- const hole = ctx.groups.holeGroup.selectAll(`.${ctx.classes.boreHole.rect}`).data(data.bore_hole);
1010
- hole.exit().remove();
1011
- const newHole = hole.enter().append("rect").attr("class", ctx.classes.boreHole.rect).attr("fill", ctx.theme.boreHole.fill).attr("stroke", ctx.theme.boreHole.stroke).attr("opacity", ctx.theme.boreHole.opacity).attr("stroke-width", ctx.theme.boreHole.strokeWidth).attr("stroke-dasharray", ctx.theme.boreHole.strokeDasharray).on("mouseover", ctx.tooltips.hole.show).on("mouseout", ctx.tooltips.hole.hide);
1012
- const mergedHole = mergeEnter(newHole, hole).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1013
- withTransition(mergedHole, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1014
- const surfaceCaseGs = ctx.groups.surfaceCaseGroup.selectAll(`g.${ctx.classes.surfaceCase.rect}`).data(data.surface_case);
1027
+ const hole = ctx.groups.holeGroup.selectAll(`.${ctx.classes.boreHole.rect}`).data(data.bore_hole, stableLayerKey);
1028
+ hole.exit().transition(ctx.transition).attr("height", 0).remove();
1029
+ const newHole = hole.enter().append("rect").attr("class", ctx.classes.boreHole.rect).attr("fill", ctx.theme.boreHole.fill).attr("stroke", ctx.theme.boreHole.stroke).attr("stroke-width", ctx.theme.boreHole.strokeWidth).attr("stroke-dasharray", ctx.theme.boreHole.strokeDasharray).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("y", getYPos).attr("height", getHeight).attr("opacity", 0).on("mouseover", ctx.tooltips.hole.show).on("mouseout", ctx.tooltips.hole.hide);
1030
+ withTransition(newHole, ctx.transition).attr(
1031
+ "opacity",
1032
+ ctx.theme.boreHole.opacity
1033
+ );
1034
+ hole.attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1035
+ withTransition(hole, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1036
+ const surfaceCaseGs = ctx.groups.surfaceCaseGroup.selectAll(`g.${ctx.classes.surfaceCase.rect}`).data(data.surface_case, stableLayerKey);
1015
1037
  surfaceCaseGs.exit().transition(ctx.transition).style("opacity", 0).remove();
1016
- const newSC = surfaceCaseGs.enter().append("g").attr("class", ctx.classes.surfaceCase.rect).on("mouseover", ctx.tooltips.surfaceCase.show).on("mouseout", ctx.tooltips.surfaceCase.hide);
1038
+ const newSC = surfaceCaseGs.enter().append("g").attr("class", ctx.classes.surfaceCase.rect).style("opacity", 0).on("mouseover", ctx.tooltips.surfaceCase.show).on("mouseout", ctx.tooltips.surfaceCase.hide);
1017
1039
  newSC.append("rect").attr("class", "surface-case-fill").attr("stroke", "none");
1018
1040
  newSC.append("line").attr("class", "surface-case-side").attr("stroke", ctx.theme.surfaceCase.stroke).attr("stroke-width", ctx.theme.surfaceCase.strokeWidth);
1019
1041
  newSC.append("line").attr("class", "surface-case-side").attr("stroke", ctx.theme.surfaceCase.stroke).attr("stroke-width", ctx.theme.surfaceCase.strokeWidth);
1020
- const mergedSC = mergeEnter(newSC, surfaceCaseGs);
1021
- mergedSC.each((d, i, nodes) => {
1042
+ newSC.each((d, i, nodes) => {
1043
+ const x = (ctx.POCO_CENTER - xScale(
1044
+ d.diameter + d.diameter * rcc.surfaceCase.diameterPaddingRatio
1045
+ )) / 2;
1046
+ const w = xScale(
1047
+ d.diameter + d.diameter * rcc.surfaceCase.diameterPaddingRatio
1048
+ );
1049
+ const g = d33.select(nodes[i]);
1050
+ g.select(".surface-case-fill").attr("x", x).attr("width", w).attr("fill", ctx.textures.surface_case.url()).attr("y", getYPos(d)).attr("height", getHeight(d));
1051
+ const sideNodes = g.selectAll(".surface-case-side").nodes();
1052
+ d33.select(sideNodes[0]).attr("x1", x).attr("x2", x).attr("y1", getYPos(d)).attr("y2", getYPos(d) + getHeight(d));
1053
+ d33.select(sideNodes[1]).attr("x1", x + w).attr("x2", x + w).attr("y1", getYPos(d)).attr("y2", getYPos(d) + getHeight(d));
1054
+ });
1055
+ withTransition(newSC, ctx.transition).style("opacity", 1);
1056
+ surfaceCaseGs.each((d, i, nodes) => {
1022
1057
  const x = (ctx.POCO_CENTER - xScale(
1023
1058
  d.diameter + d.diameter * rcc.surfaceCase.diameterPaddingRatio
1024
1059
  )) / 2;
@@ -1032,37 +1067,44 @@ function drawConstructive(ctx, data) {
1032
1067
  d33.select(sideNodes[1]).attr("x1", x + w).attr("x2", x + w);
1033
1068
  });
1034
1069
  withTransition(
1035
- mergedSC.select(".surface-case-fill"),
1070
+ surfaceCaseGs.select(".surface-case-fill"),
1036
1071
  ctx.transition
1037
1072
  ).attr("y", (d) => getYPos(d)).attr("height", (d) => getHeight(d));
1038
- mergedSC.selectAll(".surface-case-side").attr("y1", (d) => getYPos(d)).attr(
1073
+ withTransition(
1074
+ surfaceCaseGs.selectAll(".surface-case-side"),
1075
+ ctx.transition
1076
+ ).attr("y1", (d) => getYPos(d)).attr(
1039
1077
  "y2",
1040
1078
  (d) => getYPos(d) + getHeight(d)
1041
1079
  );
1042
- const holeFill = ctx.groups.holeFillGroup.selectAll(`.${ctx.classes.holeFill.rect}`).data(data.hole_fill);
1043
- holeFill.exit().remove();
1044
- const newHoleFill = holeFill.enter().append("rect").attr("class", ctx.classes.holeFill.rect).attr("stroke", ctx.theme.holeFill.stroke).attr("stroke-width", ctx.theme.holeFill.strokeWidth).on("mouseover", ctx.tooltips.holeFill.show).on("mouseout", ctx.tooltips.holeFill.hide);
1045
- const mergedHoleFill = mergeEnter(newHoleFill, holeFill).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1046
- withTransition(mergedHoleFill, ctx.transition).attr("y", getYPos).attr("height", getHeight).attr("fill", (d) => ctx.textures[d.type].url());
1047
- const wellCase = ctx.groups.wellCaseGroup.selectAll(`.${ctx.classes.wellCase.rect}`).data(data.well_case);
1048
- wellCase.exit().remove();
1049
- const newWellCase = wellCase.enter().append("rect").attr("class", ctx.classes.wellCase.rect).attr("fill", ctx.theme.wellCase.fill).attr("stroke", ctx.theme.wellCase.stroke).attr("stroke-width", ctx.theme.wellCase.strokeWidth).on("mouseover", ctx.tooltips.wellCase.show).on("mouseout", ctx.tooltips.wellCase.hide);
1050
- const mergedWellCase = mergeEnter(newWellCase, wellCase).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1051
- withTransition(mergedWellCase, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1052
- const wellScreen = ctx.groups.wellScreenGroup.selectAll(`.${ctx.classes.wellScreen.rect}`).data(data.well_screen);
1053
- wellScreen.exit().remove();
1054
- const newWellScreen = wellScreen.enter().append("rect").attr("class", ctx.classes.wellScreen.rect).attr("fill", ctx.textures.well_screen.url()).attr("stroke", ctx.theme.wellScreen.stroke).attr("stroke-width", ctx.theme.wellScreen.strokeWidth).on("mouseover", ctx.tooltips.wellScreen.show).on("mouseout", ctx.tooltips.wellScreen.hide);
1055
- const mergedWellScreen = mergeEnter(newWellScreen, wellScreen).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1056
- withTransition(mergedWellScreen, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1080
+ const holeFill = ctx.groups.holeFillGroup.selectAll(`.${ctx.classes.holeFill.rect}`).data(data.hole_fill, stableLayerKey);
1081
+ holeFill.exit().transition(ctx.transition).attr("height", 0).remove();
1082
+ const newHoleFill = holeFill.enter().append("rect").attr("class", ctx.classes.holeFill.rect).attr("stroke", ctx.theme.holeFill.stroke).attr("stroke-width", ctx.theme.holeFill.strokeWidth).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("y", getYPos).attr("height", getHeight).attr("fill", (d) => ctx.textures[d.type].url()).attr("opacity", 0).on("mouseover", ctx.tooltips.holeFill.show).on("mouseout", ctx.tooltips.holeFill.hide);
1083
+ withTransition(newHoleFill, ctx.transition).attr("opacity", 1);
1084
+ holeFill.attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("fill", (d) => ctx.textures[d.type].url());
1085
+ withTransition(holeFill, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1086
+ const wellCase = ctx.groups.wellCaseGroup.selectAll(`.${ctx.classes.wellCase.rect}`).data(data.well_case, stableLayerKey);
1087
+ wellCase.exit().transition(ctx.transition).attr("height", 0).remove();
1088
+ const newWellCase = wellCase.enter().append("rect").attr("class", ctx.classes.wellCase.rect).attr("fill", ctx.theme.wellCase.fill).attr("stroke", ctx.theme.wellCase.stroke).attr("stroke-width", ctx.theme.wellCase.strokeWidth).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("y", getYPos).attr("height", getHeight).attr("opacity", 0).on("mouseover", ctx.tooltips.wellCase.show).on("mouseout", ctx.tooltips.wellCase.hide);
1089
+ withTransition(newWellCase, ctx.transition).attr("opacity", 1);
1090
+ wellCase.attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1091
+ withTransition(wellCase, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1092
+ const wellScreen = ctx.groups.wellScreenGroup.selectAll(`.${ctx.classes.wellScreen.rect}`).data(data.well_screen, stableLayerKey);
1093
+ wellScreen.exit().transition(ctx.transition).attr("height", 0).remove();
1094
+ const newWellScreen = wellScreen.enter().append("rect").attr("class", ctx.classes.wellScreen.rect).attr("fill", ctx.textures.well_screen.url()).attr("stroke", ctx.theme.wellScreen.stroke).attr("stroke-width", ctx.theme.wellScreen.strokeWidth).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("y", getYPos).attr("height", getHeight).attr("opacity", 0).on("mouseover", ctx.tooltips.wellScreen.show).on("mouseout", ctx.tooltips.wellScreen.hide);
1095
+ withTransition(newWellScreen, ctx.transition).attr("opacity", 1);
1096
+ wellScreen.attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1097
+ withTransition(wellScreen, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1057
1098
  const conflictAreas = [];
1058
1099
  conflictAreas.push(...getConflictAreas(data.well_case, data.well_screen));
1059
1100
  conflictAreas.push(...getConflictAreas(data.well_screen, data.well_case));
1060
1101
  const mergedConflicts = mergeConflicts(conflictAreas, 1);
1061
- const conflict = ctx.groups.conflictGroup.selectAll(`.${ctx.classes.conflict.rect}`).data(mergedConflicts);
1062
- conflict.exit().remove();
1063
- const newConflict = conflict.enter().append("rect").attr("class", ctx.classes.conflict.rect).attr("fill", ctx.textures.conflict.url()).attr("stroke", ctx.theme.conflict.stroke).attr("stroke-width", ctx.theme.conflict.strokeWidth).on("mouseover", ctx.tooltips.conflict.show).on("mouseout", ctx.tooltips.conflict.hide);
1064
- const mergedConflict = mergeEnter(newConflict, conflict).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1065
- withTransition(mergedConflict, ctx.transition).attr("y", ctx.yScale(0)).attr("height", getHeight);
1102
+ const conflict = ctx.groups.conflictGroup.selectAll(`.${ctx.classes.conflict.rect}`).data(mergedConflicts, (d) => `${d.from}_${d.to}_${d.diameter}`);
1103
+ conflict.exit().transition(ctx.transition).attr("height", 0).remove();
1104
+ const newConflict = conflict.enter().append("rect").attr("class", ctx.classes.conflict.rect).attr("fill", ctx.textures.conflict.url()).attr("stroke", ctx.theme.conflict.stroke).attr("stroke-width", ctx.theme.conflict.strokeWidth).attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter)).attr("y", getYPos).attr("height", getHeight).attr("opacity", 0).on("mouseover", ctx.tooltips.conflict.show).on("mouseout", ctx.tooltips.conflict.hide);
1105
+ withTransition(newConflict, ctx.transition).attr("opacity", 1);
1106
+ conflict.attr("x", (d) => (ctx.POCO_CENTER - xScale(d.diameter)) / 2).attr("width", (d) => xScale(d.diameter));
1107
+ withTransition(conflict, ctx.transition).attr("y", getYPos).attr("height", getHeight);
1066
1108
  }
1067
1109
 
1068
1110
  // src/renderers/fractures.renderer.ts
@@ -1542,11 +1584,13 @@ function drawLithology(ctx, data) {
1542
1584
  from: depthFrom,
1543
1585
  to: depthTo
1544
1586
  });
1545
- const rects = lithologyGroup.selectAll(`.${classes.lithology.rect}`).data(data);
1546
- rects.exit().remove();
1547
- const newLayers = rects.enter().append("rect").attr("class", classes.lithology.rect).attr("x", geoXLeft).attr("width", geoXRight - geoXLeft).attr("stroke", theme.lithology.stroke).attr("stroke-width", theme.lithology.strokeWidth).on("mouseover", tooltips.geology.show).on("mouseout", tooltips.geology.hide);
1548
- const merged = mergeEnter(newLayers, rects).attr("y", getYPos);
1549
- withTransition(merged, transition).attr("height", getHeight).attr("fill", getLithologyFill(data, svg, ctx.theme.lithologyTexture));
1587
+ const fillFn = getLithologyFill(data, svg, ctx.theme.lithologyTexture);
1588
+ const rects = lithologyGroup.selectAll(`.${classes.lithology.rect}`).data(data, stableLayerKey);
1589
+ rects.exit().transition(transition).attr("height", 0).remove();
1590
+ const newLayers = rects.enter().append("rect").attr("class", classes.lithology.rect).attr("x", geoXLeft).attr("width", geoXRight - geoXLeft).attr("stroke", theme.lithology.stroke).attr("stroke-width", theme.lithology.strokeWidth).attr("y", getYPos).attr("height", getHeight).attr("fill", fillFn).attr("opacity", 0).on("mouseover", tooltips.geology.show).on("mouseout", tooltips.geology.hide);
1591
+ withTransition(newLayers, transition).attr("opacity", 1);
1592
+ rects.attr("fill", fillFn);
1593
+ withTransition(rects, transition).attr("y", getYPos).attr("height", getHeight);
1550
1594
  }
1551
1595
 
1552
1596
  // src/renderers/unit-labels.renderer.ts