@webviz/well-log-viewer 0.0.1-alpha.1 → 0.0.1-alpha.3
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/SyncLogViewer.js +3 -4
- package/dist/SyncLogViewer.js.map +1 -1
- package/dist/components/WellLogView.js +5 -5
- package/dist/components/WellLogView.js.map +1 -1
- package/dist/demo/example-data/welllog_template_2.json +167 -167
- package/dist/demo/example-data/wellpick_colors.json +1 -1
- package/dist/demo/example-data/wellpicks.json +179 -179
- package/package.json +32 -5
- package/dist/Intro.stories.mdx +0 -59
- package/dist/package.json +0 -21
- package/src/Intro.stories.mdx +0 -59
- package/src/MapAndWellLogViewer.stories.jsx +0 -147
- package/src/MapAndWellLogViewer.test.tsx +0 -26
- package/src/MapAndWellLogViewer.tsx +0 -473
- package/src/SyncLogViewer.stories.jsx +0 -361
- package/src/SyncLogViewer.test.tsx +0 -41
- package/src/SyncLogViewer.tsx +0 -1188
- package/src/WellLogViewer.png +0 -0
- package/src/WellLogViewer.stories.jsx +0 -169
- package/src/WellLogViewer.test.tsx +0 -53
- package/src/WellLogViewer.tsx +0 -439
- package/src/WellLogViewer_performance.test.tsx +0 -78
- package/src/__snapshots__/MapAndWellLogViewer.test.tsx.snap +0 -365
- package/src/__snapshots__/SyncLogViewer.test.tsx.snap +0 -510
- package/src/__snapshots__/WellLogViewer.test.tsx.snap +0 -552
- package/src/components/AxisSelector.test.tsx +0 -50
- package/src/components/AxisSelector.tsx +0 -49
- package/src/components/ColorTableTypes.ts +0 -9
- package/src/components/InfoPanel.test.tsx +0 -58
- package/src/components/InfoPanel.tsx +0 -144
- package/src/components/InfoTypes.ts +0 -17
- package/src/components/LocalMenus.tsx +0 -336
- package/src/components/PlotDialog.tsx +0 -419
- package/src/components/Scroller.stories.jsx +0 -80
- package/src/components/Scroller.test.tsx +0 -22
- package/src/components/Scroller.tsx +0 -173
- package/src/components/TrackDialog.tsx +0 -217
- package/src/components/WellLogSpacer.tsx +0 -483
- package/src/components/WellLogTemplateTypes.ts +0 -65
- package/src/components/WellLogTypes.ts +0 -53
- package/src/components/WellLogView.stories.jsx +0 -84
- package/src/components/WellLogView.test.tsx +0 -52
- package/src/components/WellLogView.tsx +0 -2063
- package/src/components/WellLogViewWithScroller.stories.jsx +0 -69
- package/src/components/WellLogViewWithScroller.test.tsx +0 -47
- package/src/components/WellLogViewWithScroller.tsx +0 -179
- package/src/components/ZoomSlider.stories.jsx +0 -52
- package/src/components/ZoomSlider.test.tsx +0 -28
- package/src/components/ZoomSlider.tsx +0 -86
- package/src/components/__snapshots__/AxisSelector.test.tsx.snap +0 -28
- package/src/components/__snapshots__/InfoPanel.test.tsx.snap +0 -103
- package/src/components/__snapshots__/Scroller.test.tsx.snap +0 -13
- package/src/components/__snapshots__/WellLogView.test.tsx.snap +0 -54
- package/src/components/__snapshots__/WellLogViewWithScroller.test.tsx.snap +0 -270
- package/src/components/__snapshots__/ZoomSlider.test.tsx.snap +0 -50
- package/src/components/styles.scss +0 -106
- package/src/custom.d.ts +0 -13
- package/src/demo/example-data/volve_logs.json +0 -689617
- package/src/demo/example-data/welllog_template_2.json +0 -196
- package/src/demo/example-data/wellpick_colors.json +0 -156
- package/src/demo/example-data/wellpicks.json +0 -186
- package/src/index.ts +0 -8
- package/src/utils/axes.ts +0 -26
- package/src/utils/color-table.ts +0 -153
- package/src/utils/deepcopy.ts +0 -3
- package/src/utils/edit-track.tsx +0 -40
- package/src/utils/fill-info.ts +0 -224
- package/src/utils/gradientfill-plot-legend.ts +0 -177
- package/src/utils/gradientfill-plot.ts +0 -203
- package/src/utils/graph/factory.ts +0 -15
- package/src/utils/legend/common.ts +0 -153
- package/src/utils/log-viewer.ts +0 -209
- package/src/utils/minmax.ts +0 -126
- package/src/utils/pattern.tsx +0 -50
- package/src/utils/stack/stack-legend.ts +0 -100
- package/src/utils/tracks.ts +0 -1559
- package/tsconfig.json +0 -8
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { area } from "d3";
|
|
2
|
-
import { Scale } from "@equinor/videx-wellog/dist/common/interfaces";
|
|
3
|
-
import { Plot } from "@equinor/videx-wellog";
|
|
4
|
-
|
|
5
|
-
import { DefinedFunction } from "@equinor/videx-wellog/dist/plots/interfaces";
|
|
6
|
-
|
|
7
|
-
import renderGradientFillPlotLegend from "./gradientfill-plot-legend";
|
|
8
|
-
import { getInterpolatedColorString } from "./color-table";
|
|
9
|
-
|
|
10
|
-
import { ColorTable } from "../components/ColorTableTypes";
|
|
11
|
-
|
|
12
|
-
import { AreaPlotOptions } from "@equinor/videx-wellog/dist/plots/interfaces";
|
|
13
|
-
|
|
14
|
-
export interface GradientFillPlotOptions extends AreaPlotOptions {
|
|
15
|
-
colorTable?: ColorTable;
|
|
16
|
-
inverseColorTable?: ColorTable;
|
|
17
|
-
colorScale?: "linear" | "log";
|
|
18
|
-
inverseColorScale?: "linear" | "log";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Create gradient based on colorTable
|
|
23
|
-
*/
|
|
24
|
-
function createGradient(
|
|
25
|
-
ctx: CanvasRenderingContext2D,
|
|
26
|
-
yscale: Scale,
|
|
27
|
-
horizontal: boolean | undefined,
|
|
28
|
-
plotdata: number[][],
|
|
29
|
-
xscale: Scale,
|
|
30
|
-
colorTable: ColorTable,
|
|
31
|
-
scale: undefined | string // "linear" | "log"
|
|
32
|
-
): CanvasGradient {
|
|
33
|
-
const dataFrom = plotdata[0];
|
|
34
|
-
const dataTo = plotdata[plotdata.length - 1];
|
|
35
|
-
const sFrom = yscale(dataFrom[0]);
|
|
36
|
-
const sTo = yscale(dataTo[0]);
|
|
37
|
-
|
|
38
|
-
const gradient: CanvasGradient = horizontal
|
|
39
|
-
? ctx.createLinearGradient(sFrom, 0, sTo, 0)
|
|
40
|
-
: ctx.createLinearGradient(0, sFrom, 0, sTo);
|
|
41
|
-
|
|
42
|
-
if (scale === "log") {
|
|
43
|
-
const [min, max] = xscale.domain();
|
|
44
|
-
const xFrom = dataFrom[0];
|
|
45
|
-
const xDelta = dataTo[0] - xFrom;
|
|
46
|
-
const yFrom = Math.log(min);
|
|
47
|
-
const yDelta = Math.log(max) - yFrom;
|
|
48
|
-
for (const data of plotdata) {
|
|
49
|
-
const stop = (data[0] - xFrom) / xDelta;
|
|
50
|
-
if (0 <= stop && stop <= 1.0) {
|
|
51
|
-
const v = (Math.log(data[1]) - yFrom) / yDelta;
|
|
52
|
-
const c = getInterpolatedColorString(colorTable, v);
|
|
53
|
-
gradient.addColorStop(stop, c);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
// "linear"
|
|
58
|
-
const xFrom = dataFrom[0];
|
|
59
|
-
const xDelta = dataTo[0] - xFrom;
|
|
60
|
-
const yFrom = xscale.domain()[0];
|
|
61
|
-
const yDelta = xscale.domain()[1] - yFrom;
|
|
62
|
-
for (const data of plotdata) {
|
|
63
|
-
// TODO: add some additional intermediate stop positions when y changes significantly
|
|
64
|
-
// and color-table stops exists between consequent y values
|
|
65
|
-
const stop = (data[0] - xFrom) / xDelta;
|
|
66
|
-
if (0 <= stop && stop <= 1.0) {
|
|
67
|
-
const v = (data[1] - yFrom) / yDelta;
|
|
68
|
-
const c = getInterpolatedColorString(colorTable, v);
|
|
69
|
-
gradient.addColorStop(stop, c);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return gradient;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* GradientFill plot
|
|
79
|
-
*/
|
|
80
|
-
export default class GradientFillPlot extends Plot {
|
|
81
|
-
constructor(id: string | number, options: GradientFillPlotOptions = {}) {
|
|
82
|
-
super(id, options);
|
|
83
|
-
// subclass render function.
|
|
84
|
-
// eslint-disable-next-line
|
|
85
|
-
(this.options as any).renderLegend = renderGradientFillPlotLegend; // see updateLegendRows() in videx-wellog\src\tracks\graph\graph-legend.ts
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Renders area plot to canvas context
|
|
90
|
-
* @param ctx canvas context instance
|
|
91
|
-
* @param scale y-scale
|
|
92
|
-
*/
|
|
93
|
-
plot(ctx: CanvasRenderingContext2D, scale: Scale): void {
|
|
94
|
-
const { scale: xscale, data: plotdata } = this;
|
|
95
|
-
if (!xscale) return;
|
|
96
|
-
|
|
97
|
-
const options = this.options as GradientFillPlotOptions;
|
|
98
|
-
if (options.hidden) return;
|
|
99
|
-
|
|
100
|
-
const useMinAsBase =
|
|
101
|
-
options.useMinAsBase === undefined ? true : options.useMinAsBase;
|
|
102
|
-
|
|
103
|
-
const [d0, d1] = xscale.domain();
|
|
104
|
-
const dmin = Math.min(d0, d1);
|
|
105
|
-
const dmax = Math.max(d0, d1);
|
|
106
|
-
|
|
107
|
-
const rmin = xscale(dmin);
|
|
108
|
-
const rmax = xscale(dmax);
|
|
109
|
-
|
|
110
|
-
const zeroValue = useMinAsBase ? rmin : rmax;
|
|
111
|
-
|
|
112
|
-
ctx.save();
|
|
113
|
-
|
|
114
|
-
const areaFunction = area()
|
|
115
|
-
// this.options.defined is always initialized by some function
|
|
116
|
-
.defined((d) => (options.defined as DefinedFunction)(d[1], d[0]))
|
|
117
|
-
.context(ctx);
|
|
118
|
-
|
|
119
|
-
if (options.horizontal) {
|
|
120
|
-
areaFunction
|
|
121
|
-
.y1((d) => xscale(d[1]))
|
|
122
|
-
.y0(zeroValue)
|
|
123
|
-
.x((d) => scale(d[0]));
|
|
124
|
-
} else {
|
|
125
|
-
areaFunction
|
|
126
|
-
.x1((d) => xscale(d[1]))
|
|
127
|
-
.x0(zeroValue)
|
|
128
|
-
.y((d) => scale(d[0]));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
ctx.globalAlpha = options.fillOpacity || 1;
|
|
132
|
-
|
|
133
|
-
if (options.inverseColor || options.inverseColorTable) {
|
|
134
|
-
const inverseValue = useMinAsBase ? rmax : rmin;
|
|
135
|
-
|
|
136
|
-
const inverseAreaFunction = area()
|
|
137
|
-
// this.options.defined is always initialized by some function
|
|
138
|
-
.defined((d) =>
|
|
139
|
-
(options.defined as DefinedFunction)(d[1], d[0])
|
|
140
|
-
)
|
|
141
|
-
.context(ctx);
|
|
142
|
-
|
|
143
|
-
if (options.horizontal) {
|
|
144
|
-
inverseAreaFunction
|
|
145
|
-
.y1((d) => xscale(d[1]))
|
|
146
|
-
.y0(inverseValue)
|
|
147
|
-
.x((d) => scale(d[0]));
|
|
148
|
-
} else {
|
|
149
|
-
inverseAreaFunction
|
|
150
|
-
.x1((d) => xscale(d[1]))
|
|
151
|
-
.x0(inverseValue)
|
|
152
|
-
.y((d) => scale(d[0]));
|
|
153
|
-
}
|
|
154
|
-
ctx.beginPath();
|
|
155
|
-
inverseAreaFunction(plotdata);
|
|
156
|
-
ctx.fillStyle = options.inverseColor || "";
|
|
157
|
-
/* Start GradientFill code */
|
|
158
|
-
const colorTable = options.inverseColorTable;
|
|
159
|
-
if (colorTable)
|
|
160
|
-
ctx.fillStyle = createGradient(
|
|
161
|
-
ctx,
|
|
162
|
-
scale,
|
|
163
|
-
options.horizontal,
|
|
164
|
-
plotdata,
|
|
165
|
-
xscale,
|
|
166
|
-
colorTable,
|
|
167
|
-
options.inverseColorScale ||
|
|
168
|
-
options.colorScale ||
|
|
169
|
-
options.scale
|
|
170
|
-
);
|
|
171
|
-
/* End GradientFill code */
|
|
172
|
-
|
|
173
|
-
ctx.fill();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
ctx.beginPath();
|
|
177
|
-
areaFunction(plotdata);
|
|
178
|
-
ctx.lineWidth = options.width || 0.0;
|
|
179
|
-
|
|
180
|
-
ctx.fillStyle = options.fill || options.color || "";
|
|
181
|
-
/* Start GradientFill code */
|
|
182
|
-
const colorTable = options.colorTable;
|
|
183
|
-
if (colorTable)
|
|
184
|
-
ctx.fillStyle = createGradient(
|
|
185
|
-
ctx,
|
|
186
|
-
scale,
|
|
187
|
-
options.horizontal,
|
|
188
|
-
plotdata,
|
|
189
|
-
xscale,
|
|
190
|
-
colorTable,
|
|
191
|
-
options.colorScale || options.scale
|
|
192
|
-
);
|
|
193
|
-
/* End GradientFill code */
|
|
194
|
-
|
|
195
|
-
ctx.fill();
|
|
196
|
-
|
|
197
|
-
ctx.globalAlpha = 1;
|
|
198
|
-
ctx.strokeStyle = options.color || "";
|
|
199
|
-
ctx.stroke();
|
|
200
|
-
|
|
201
|
-
ctx.restore();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { scaleLinear, scaleLog } from "d3";
|
|
2
|
-
import { Scale, Domain } from "@equinor/videx-wellog/dist/common/interfaces";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a d3 scale from config
|
|
6
|
-
*/
|
|
7
|
-
export function createScale(type: string, domain: Domain): Scale {
|
|
8
|
-
if (type === "linear") {
|
|
9
|
-
return scaleLinear().domain(domain) as Scale;
|
|
10
|
-
}
|
|
11
|
-
if (type === "log") {
|
|
12
|
-
return scaleLog().domain(domain) as Scale;
|
|
13
|
-
}
|
|
14
|
-
throw Error("Invalid input!");
|
|
15
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/* This file contains functions wich are missed on exports from "@equinor/videx-wellog" see \src\plots\legend\common.ts */
|
|
2
|
-
|
|
3
|
-
import { setProps, setAttrs } from "@equinor/videx-wellog";
|
|
4
|
-
import { LegendBounds } from "@equinor/videx-wellog/dist/utils/legend-helper";
|
|
5
|
-
// eslint-disable-next-line
|
|
6
|
-
declare type D3Selection = any; // not exported from videx-wellog! import { D3Selection } from "@equinor/videx-wellog/dist/common/interfaces';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Renders label, min/max values for domain and unit
|
|
10
|
-
*/
|
|
11
|
-
export function renderTextLabels(
|
|
12
|
-
g: D3Selection,
|
|
13
|
-
bounds: LegendBounds,
|
|
14
|
-
label: string,
|
|
15
|
-
unit: string,
|
|
16
|
-
domain: number[],
|
|
17
|
-
color: string,
|
|
18
|
-
addLabelBg = false
|
|
19
|
-
): void {
|
|
20
|
-
const { height: h, width: w, top, left } = bounds;
|
|
21
|
-
const lineY = top + h * 0.5;
|
|
22
|
-
const textSize = h * 0.35;
|
|
23
|
-
const subTextSize = textSize * 0.85;
|
|
24
|
-
const subY = lineY + subTextSize;
|
|
25
|
-
const centerX = left + w / 2;
|
|
26
|
-
const [min, max] = domain;
|
|
27
|
-
|
|
28
|
-
// label
|
|
29
|
-
const labelX = centerX;
|
|
30
|
-
const labelY = top + textSize;
|
|
31
|
-
const labelTransform = `translate(${labelX},${labelY})`;
|
|
32
|
-
|
|
33
|
-
let labelBg;
|
|
34
|
-
if (addLabelBg) {
|
|
35
|
-
labelBg = g
|
|
36
|
-
.append("rect")
|
|
37
|
-
.classed("label-bg", true)
|
|
38
|
-
.attr("fill", "white");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const labelText = g.append("text").text(label);
|
|
42
|
-
setProps(labelText, {
|
|
43
|
-
styles: {
|
|
44
|
-
"text-anchor": "middle",
|
|
45
|
-
fill: color,
|
|
46
|
-
},
|
|
47
|
-
attrs: {
|
|
48
|
-
class: "legend-label",
|
|
49
|
-
"font-size": `${textSize}px`,
|
|
50
|
-
transform: labelTransform,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (addLabelBg) {
|
|
55
|
-
const bbox = labelText.node().getBBox();
|
|
56
|
-
setAttrs(labelBg, {
|
|
57
|
-
x: centerX + bbox.x - 1,
|
|
58
|
-
y: top + 1,
|
|
59
|
-
width: bbox.width + 2,
|
|
60
|
-
height: h * 0.5 - 2,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// unit
|
|
65
|
-
if (unit) {
|
|
66
|
-
const unitX = centerX;
|
|
67
|
-
const unitTransform = `translate(${unitX},${subY})`;
|
|
68
|
-
const unitText = g.append("text").text(unit);
|
|
69
|
-
setProps(unitText, {
|
|
70
|
-
styles: {
|
|
71
|
-
"text-anchor": "middle",
|
|
72
|
-
fill: color,
|
|
73
|
-
},
|
|
74
|
-
attrs: {
|
|
75
|
-
class: "legend-unit",
|
|
76
|
-
"font-size": `${subTextSize}px`,
|
|
77
|
-
transform: unitTransform,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const minText =
|
|
83
|
-
Math.abs(min) > 1000 && min % 1000 === 0
|
|
84
|
-
? `${Math.round(min / 1000)}k`
|
|
85
|
-
: `${min}`;
|
|
86
|
-
const maxText =
|
|
87
|
-
Math.abs(max) > 1000 && max % 1000 === 0
|
|
88
|
-
? `${Math.round(max / 1000)}k`
|
|
89
|
-
: `${max}`;
|
|
90
|
-
// domain
|
|
91
|
-
const minDomain = g.append("text").text(minText);
|
|
92
|
-
setProps(minDomain, {
|
|
93
|
-
styles: {
|
|
94
|
-
"text-anchor": "start",
|
|
95
|
-
fill: color,
|
|
96
|
-
},
|
|
97
|
-
attrs: {
|
|
98
|
-
class: "legend-domain",
|
|
99
|
-
"font-size": `${subTextSize}px`,
|
|
100
|
-
x: left + 2,
|
|
101
|
-
y: subY,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
const maxDomain = g.append("text").text(maxText);
|
|
105
|
-
setProps(maxDomain, {
|
|
106
|
-
styles: {
|
|
107
|
-
"text-anchor": "end",
|
|
108
|
-
fill: color,
|
|
109
|
-
},
|
|
110
|
-
attrs: {
|
|
111
|
-
class: "legend-domain",
|
|
112
|
-
"font-size": `${subTextSize}px`,
|
|
113
|
-
x: left + w - 2,
|
|
114
|
-
y: subY,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Renders a basic/standard set of layout that are common for most plot-type legends
|
|
121
|
-
*/
|
|
122
|
-
export function renderBasicPlotLegend(
|
|
123
|
-
g: D3Selection,
|
|
124
|
-
bounds: LegendBounds,
|
|
125
|
-
label: string,
|
|
126
|
-
unit: string,
|
|
127
|
-
domain: number[],
|
|
128
|
-
color: string,
|
|
129
|
-
addLabelBg = false
|
|
130
|
-
): void {
|
|
131
|
-
const x1 = bounds.left + 2;
|
|
132
|
-
const x2 = Math.max(x1, bounds.left + bounds.width - 2);
|
|
133
|
-
|
|
134
|
-
const lineY = bounds.top + bounds.height * 0.5;
|
|
135
|
-
const lineWidth = bounds.height * 0.1;
|
|
136
|
-
|
|
137
|
-
const line = g.append("line");
|
|
138
|
-
setProps(line, {
|
|
139
|
-
attrs: {
|
|
140
|
-
x1,
|
|
141
|
-
x2,
|
|
142
|
-
y1: lineY,
|
|
143
|
-
y2: lineY,
|
|
144
|
-
},
|
|
145
|
-
styles: {
|
|
146
|
-
"stroke-width": lineWidth,
|
|
147
|
-
stroke: color,
|
|
148
|
-
fill: color,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
renderTextLabels(g, bounds, label, unit, domain, color, addLabelBg);
|
|
153
|
-
}
|
package/src/utils/log-viewer.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { LogViewer, Track } from "@equinor/videx-wellog";
|
|
2
|
-
|
|
3
|
-
import { isScaleTrack } from "../utils/tracks";
|
|
4
|
-
|
|
5
|
-
export function removeOverlay(logViewer: LogViewer): void {
|
|
6
|
-
logViewer.container.select(".overlay").remove();
|
|
7
|
-
//logViewer.overlay = null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isTrackVisible(track: Track): boolean {
|
|
11
|
-
if (track.elm) {
|
|
12
|
-
const elm = track.elm.parentElement;
|
|
13
|
-
if (elm) {
|
|
14
|
-
return elm.style.display !== "none";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function showTrack(track: Track, visible: boolean): boolean {
|
|
21
|
-
if (track.elm) {
|
|
22
|
-
const elm = track.elm.parentElement;
|
|
23
|
-
if (elm) {
|
|
24
|
-
const display = visible ? "flex" : "none";
|
|
25
|
-
if (elm.style.display !== display) {
|
|
26
|
-
elm.style.display = display;
|
|
27
|
-
return true; // visibility is changed
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false; // visibility is not changed
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function isTrackSelected(_logViewer: LogViewer, track: Track): boolean {
|
|
35
|
-
if (track.elm) {
|
|
36
|
-
const elm = track.elm.parentElement;
|
|
37
|
-
if (elm) {
|
|
38
|
-
return elm.classList.contains("selected");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function selectTrack(
|
|
45
|
-
logViewer: LogViewer,
|
|
46
|
-
track: Track,
|
|
47
|
-
selected: boolean
|
|
48
|
-
): boolean {
|
|
49
|
-
if (track.elm) {
|
|
50
|
-
const elm = track.elm.parentElement;
|
|
51
|
-
if (elm) {
|
|
52
|
-
if (isTrackSelected(logViewer, track) !== selected) {
|
|
53
|
-
elm.classList.toggle("selected");
|
|
54
|
-
return true; // selection is changed
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false; // selection is not changed
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function getSelectedTrackIndices(logViewer?: LogViewer): number[] {
|
|
62
|
-
const selectedTrackIndices: number[] = [];
|
|
63
|
-
if (logViewer) {
|
|
64
|
-
let iTrack = 0;
|
|
65
|
-
for (const track of logViewer.tracks) {
|
|
66
|
-
if (isTrackSelected(logViewer, track))
|
|
67
|
-
selectedTrackIndices.push(iTrack);
|
|
68
|
-
iTrack++;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return selectedTrackIndices;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
///////////////////////
|
|
75
|
-
|
|
76
|
-
export function zoomContent(logViewer: LogViewer, zoom: number): boolean {
|
|
77
|
-
if (!zoom) zoom = 1.0;
|
|
78
|
-
|
|
79
|
-
const [b1, b2] = logViewer.scaleHandler.baseDomain();
|
|
80
|
-
const [d1, d2] = logViewer.domain;
|
|
81
|
-
const currentZoom = Math.abs(b2 - b1) / Math.abs(d2 - d1);
|
|
82
|
-
// see also: getContentZoom(logViewer);
|
|
83
|
-
|
|
84
|
-
const f = Math.abs(Math.log(currentZoom / zoom));
|
|
85
|
-
if (f > 0.01) {
|
|
86
|
-
/*currentZoom !~= zoom*/
|
|
87
|
-
let d = (d2 - d1) * 0.5;
|
|
88
|
-
let c = d1 + d; // the center of the visible part
|
|
89
|
-
d = d * (currentZoom / zoom);
|
|
90
|
-
// check if new domain is in the base domain
|
|
91
|
-
if (c + d > b2) c = b2 - d;
|
|
92
|
-
if (c - d < b1) c = b1 + d;
|
|
93
|
-
logViewer.zoomTo([c - d, c + d]);
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function scrollContentTo(
|
|
100
|
-
logViewer: LogViewer,
|
|
101
|
-
f: /*fraction*/ number
|
|
102
|
-
): boolean {
|
|
103
|
-
const [b1, b2] = logViewer.scaleHandler.baseDomain();
|
|
104
|
-
const [d1, d2] = logViewer.domain;
|
|
105
|
-
const d = d2 - d1;
|
|
106
|
-
const w = b2 - b1 - d; // width of not visible part of content
|
|
107
|
-
|
|
108
|
-
const c = b1 + f * w;
|
|
109
|
-
if (c !== d1) {
|
|
110
|
-
logViewer.zoomTo([c, c + d]);
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function zoomContentTo(
|
|
117
|
-
logViewer: LogViewer,
|
|
118
|
-
domain: [number, number]
|
|
119
|
-
): boolean {
|
|
120
|
-
const [d1, d2] = logViewer.domain;
|
|
121
|
-
if (domain[0] !== d1 || domain[1] !== d2) {
|
|
122
|
-
logViewer.zoomTo(domain);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function setContentBaseDomain(
|
|
129
|
-
logViewer: LogViewer,
|
|
130
|
-
domain: [number, number]
|
|
131
|
-
): void {
|
|
132
|
-
const [b1, b2] = logViewer.scaleHandler.baseDomain();
|
|
133
|
-
if (b1 !== domain[0] || b2 !== domain[1]) {
|
|
134
|
-
logViewer.domain = domain;
|
|
135
|
-
//logViewer.scaleHandler.baseDomain(domain);
|
|
136
|
-
//logViewer.rescale();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
////////// utilities
|
|
141
|
-
|
|
142
|
-
export function getContentBaseDomain(logViewer: LogViewer): [number, number] {
|
|
143
|
-
const [b1, b2] = logViewer.scaleHandler.baseDomain();
|
|
144
|
-
return [b1, b2];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function getContentDomain(logViewer: LogViewer): [number, number] {
|
|
148
|
-
const [d1, d2] = logViewer.domain;
|
|
149
|
-
return [d1, d2];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function getContentZoom(logViewer: LogViewer): number /*fraction*/ {
|
|
153
|
-
// see also zoomContent(logViewer)
|
|
154
|
-
const [b1, b2] = logViewer.scaleHandler.baseDomain();
|
|
155
|
-
const [d1, d2] = logViewer.domain;
|
|
156
|
-
return Math.abs(b2 - b1) / Math.abs(d2 - d1);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function scrollTracksTo(
|
|
160
|
-
logViewer: LogViewer,
|
|
161
|
-
iFrom: number,
|
|
162
|
-
iTo: number
|
|
163
|
-
): boolean {
|
|
164
|
-
let visibilityIsChanged = false;
|
|
165
|
-
let iTrack = 0; // non-scale (graph) tracks counter
|
|
166
|
-
for (const track of logViewer.tracks) {
|
|
167
|
-
if (isScaleTrack(track)) continue; // skip scales
|
|
168
|
-
|
|
169
|
-
const visible = iFrom <= iTrack && iTrack < iTo;
|
|
170
|
-
if (showTrack(track, visible)) visibilityIsChanged = true;
|
|
171
|
-
|
|
172
|
-
iTrack++;
|
|
173
|
-
}
|
|
174
|
-
if (visibilityIsChanged) logViewer.updateTracks();
|
|
175
|
-
return visibilityIsChanged;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function getFirstVisibleTrack(logViewer: LogViewer): number {
|
|
179
|
-
let iTrack = 0; // non-scale (graph) tracks counter
|
|
180
|
-
for (const track of logViewer.tracks) {
|
|
181
|
-
if (isScaleTrack(track)) continue; // skip scales
|
|
182
|
-
|
|
183
|
-
if (isTrackVisible(track)) return iTrack;
|
|
184
|
-
iTrack++;
|
|
185
|
-
}
|
|
186
|
-
return -1;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function setSelectedTrackIndices(
|
|
190
|
-
logViewer: LogViewer | undefined,
|
|
191
|
-
selectedTrackIndices: number[]
|
|
192
|
-
): boolean {
|
|
193
|
-
let changed = false;
|
|
194
|
-
if (logViewer && selectedTrackIndices) {
|
|
195
|
-
let iTrack = 0;
|
|
196
|
-
for (const track of logViewer.tracks) {
|
|
197
|
-
const selected = selectedTrackIndices.indexOf(iTrack) >= 0;
|
|
198
|
-
if (selectTrack(logViewer, track, selected)) changed = true;
|
|
199
|
-
iTrack++;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return changed;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export function updateLegendRows(logViewer: LogViewer): void {
|
|
206
|
-
// access protected member function
|
|
207
|
-
// eslint-disable-next-line
|
|
208
|
-
(logViewer as any).updateLegendRows();
|
|
209
|
-
}
|
package/src/utils/minmax.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
export function checkMinMaxValue(
|
|
2
|
-
minmax: [number, number],
|
|
3
|
-
value: number
|
|
4
|
-
): void {
|
|
5
|
-
if (value !== null) {
|
|
6
|
-
if (minmax[0] === Number.POSITIVE_INFINITY)
|
|
7
|
-
minmax[0] = minmax[1] = value;
|
|
8
|
-
else if (minmax[0] > value) minmax[0] = value;
|
|
9
|
-
else if (minmax[1] < value) minmax[1] = value;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function checkMinMax(
|
|
14
|
-
minmax: [number, number],
|
|
15
|
-
minmaxSrc: [number, number]
|
|
16
|
-
): void {
|
|
17
|
-
if (minmax[0] === Number.POSITIVE_INFINITY) {
|
|
18
|
-
minmax[0] = minmaxSrc[0];
|
|
19
|
-
minmax[1] = minmaxSrc[1];
|
|
20
|
-
} else {
|
|
21
|
-
if (minmax[0] > minmaxSrc[0]) minmax[0] = minmaxSrc[0];
|
|
22
|
-
if (minmax[1] < minmaxSrc[1]) minmax[1] = minmaxSrc[1];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function roundMinMax(minmax: [number, number]): [number, number] {
|
|
27
|
-
const kmin = 6; // a minimal number of intervals
|
|
28
|
-
const kmax = 9; // a maximal number of intervals
|
|
29
|
-
|
|
30
|
-
let mi = minmax[0];
|
|
31
|
-
let ma = minmax[1];
|
|
32
|
-
|
|
33
|
-
if (!isFinite(mi) || !isFinite(ma)) return [mi, ma];
|
|
34
|
-
|
|
35
|
-
if (!mi && !ma)
|
|
36
|
-
// some special case of absolutly round values (zeroes)
|
|
37
|
-
return [mi, ma];
|
|
38
|
-
|
|
39
|
-
let d = ma - mi;
|
|
40
|
-
if (d < 0) return [mi, ma];
|
|
41
|
-
if (!d) d = 1;
|
|
42
|
-
else {
|
|
43
|
-
// avoid rounding of already near round values (some round decimals do not have exact the binary representation)
|
|
44
|
-
ma = ma - d * 0.0000001;
|
|
45
|
-
mi = mi + d * 0.0000001;
|
|
46
|
-
d = ma - mi;
|
|
47
|
-
}
|
|
48
|
-
const l0 = Math.floor(Math.log10(d));
|
|
49
|
-
let p = Math.pow(10, l0 + 1);
|
|
50
|
-
let c = (mi + d * 0.5) / p;
|
|
51
|
-
if (Math.abs(c) > 1e9) c *= p;
|
|
52
|
-
else c = Math.floor(c) * p;
|
|
53
|
-
let q = 0.5;
|
|
54
|
-
let l = l0;
|
|
55
|
-
|
|
56
|
-
let k1 = 0,
|
|
57
|
-
k2 = 0;
|
|
58
|
-
let k = k2 - k1;
|
|
59
|
-
for (; l > -20 /*-30*/; l--) {
|
|
60
|
-
p = p * 0.1;
|
|
61
|
-
while (q >= 0.5) {
|
|
62
|
-
d = p * q;
|
|
63
|
-
k2 = Math.floor((ma - c) / d);
|
|
64
|
-
if (ma >= c) k2++;
|
|
65
|
-
k1 = Math.floor((mi - c) / d);
|
|
66
|
-
if (mi < c) k1--;
|
|
67
|
-
k = k2 - k1;
|
|
68
|
-
if (k >= kmax) break;
|
|
69
|
-
q = q * 0.5;
|
|
70
|
-
}
|
|
71
|
-
if (k >= kmax) break;
|
|
72
|
-
q = 2.0;
|
|
73
|
-
}
|
|
74
|
-
if (k >= kmax) {
|
|
75
|
-
for (; l < l0; l++) {
|
|
76
|
-
while (q <= 2.0) {
|
|
77
|
-
d = p * q;
|
|
78
|
-
k2 = Math.floor((ma - c) / d);
|
|
79
|
-
if (ma >= c) k2++;
|
|
80
|
-
k1 = Math.floor((mi - c) / d);
|
|
81
|
-
if (mi < c) k1--;
|
|
82
|
-
k = k2 - k1;
|
|
83
|
-
if (k <= kmax) break;
|
|
84
|
-
q = q * 2.0;
|
|
85
|
-
}
|
|
86
|
-
if (k <= kmax) break;
|
|
87
|
-
q = 0.5;
|
|
88
|
-
p = p * 10;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (k < kmin) {
|
|
92
|
-
const j = q == 2.0 ? 5 : 2;
|
|
93
|
-
if (k1 >= 0) k = (k1 / j) * j;
|
|
94
|
-
else k = ((k1 - j + 1) / j) * j;
|
|
95
|
-
if (k2 - k > kmin) {
|
|
96
|
-
if (k2 < 0) k = (k2 / j) * j;
|
|
97
|
-
else k = ((k2 + j - 1) / j) * j;
|
|
98
|
-
if (k - k1 > kmin) k2 = (k2 + k1 + kmin) / 2;
|
|
99
|
-
else k2 = k;
|
|
100
|
-
} else {
|
|
101
|
-
k1 = k2 - kmin;
|
|
102
|
-
k2 = k1 + kmin;
|
|
103
|
-
}
|
|
104
|
-
k1 = k;
|
|
105
|
-
}
|
|
106
|
-
const a = k1 * d + c;
|
|
107
|
-
const b = k2 * d + c;
|
|
108
|
-
return [parseFloat(a.toPrecision(5)), parseFloat(b.toPrecision(5))];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function roundLogMinMax(minmax: [number, number]): [number, number] {
|
|
112
|
-
const r = roundMinMax(minmax);
|
|
113
|
-
/* TODO: make Log version
|
|
114
|
-
const ret = roundMinMax([Math.log10(minmax[0]), Math.log10(minmax[1])]);
|
|
115
|
-
//const a=Math.pow(10, ret[0]), b=Math.pow(10, ret[1]);
|
|
116
|
-
*/
|
|
117
|
-
if (r[0] <= 0) {
|
|
118
|
-
// avoid non-positive values
|
|
119
|
-
r[0] = minmax[0];
|
|
120
|
-
if (r[0] <= 0) {
|
|
121
|
-
// could not show negative data!
|
|
122
|
-
console.error("Wrong data range for logarithm scale " + minmax);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return [parseFloat(r[0].toPrecision(5)), parseFloat(r[1].toPrecision(5))];
|
|
126
|
-
}
|