mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Merge pull request #38129 from ClickHouse/revert-38043-revert-37810-trace-d3-gantt
Revert "Revert "add d3js based trace visualizer as gantt chart""
This commit is contained in:
commit
f203ef3536
@ -5,7 +5,7 @@
|
||||
ROOT_PATH=$(git rev-parse --show-toplevel)
|
||||
|
||||
codespell \
|
||||
--skip "*generated*,*gperf*,*.bin,*.mrk*,*.idx,checksums.txt,*.dat,*.pyc,*.kate-swp,*obfuscateQueries.cpp,${ROOT_PATH}/utils/check-style/aspell-ignore" \
|
||||
--skip "*generated*,*gperf*,*.bin,*.mrk*,*.idx,checksums.txt,*.dat,*.pyc,*.kate-swp,*obfuscateQueries.cpp,d3-*.js,*.min.js,${ROOT_PATH}/utils/check-style/aspell-ignore" \
|
||||
--ignore-words "${ROOT_PATH}/utils/check-style/codespell-ignore-words.list" \
|
||||
--exclude-file "${ROOT_PATH}/utils/check-style/codespell-ignore-lines.list" \
|
||||
--quiet-level 2 \
|
||||
|
36
utils/trace-visualizer/README.md
Normal file
36
utils/trace-visualizer/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
Trace visualizer is a tool for representation of a tracing data as a Gantt diagram.
|
||||
|
||||
# Quick start
|
||||
For now this tool is not integrated into ClickHouse and requires a lot of manual adjustments.
|
||||
```bash
|
||||
cd utils/trace-visualizer
|
||||
python3 -m http.server
|
||||
```
|
||||
Open [localhost](http://localhost:8000). It will show an example of data. To show your tracing data you have to put it in JSON format near `index.html` and change call to `fetchData()` function at the bottom of `index.html`. (Do not forget to disable browser caching while changing it).
|
||||
|
||||
# Visualizing query trace
|
||||
First of all [opentelemetry_span_log](https://clickhouse.com/docs/en/operations/opentelemetry/) system table must be enabled to save query traces. Then run a query you want to trace with a setting:
|
||||
```sql
|
||||
set opentelemetry_start_trace_probability=1;
|
||||
SELECT 1;
|
||||
```
|
||||
|
||||
To find out `trace_id` of a query run the following command:
|
||||
```sql
|
||||
SELECT DISTINCT trace_id FROM system.opentelemetry_span_log ORDER BY query_start_time DESC;
|
||||
```
|
||||
|
||||
To obtain JSON data suitable for visualizing run:
|
||||
```sql
|
||||
SELECT tuple (parent_span_id, attribute['clickhouse.thread_id'] || attribute['thread_number'] as thread_id)::Tuple(parent_span_id UInt64, thread_id String) as group, operation_name, start_time_us, finish_time_us, sipHash64(operation_name) as color, attribute
|
||||
from system.opentelemetry_span_log
|
||||
WHERE trace_id = 'your-trace-id'
|
||||
ORDER BY group ASC
|
||||
FORMAT JSON SETTINGS output_format_json_named_tuples_as_objects = 1;
|
||||
```
|
||||
|
||||
# Dependencies
|
||||
1. [D3js](https://github.com/d3/d3) (v4).
|
||||
2. [Tooltips for D3](https://github.com/caged/d3-tip).
|
||||
3. [jquery](https://github.com/jquery/jquery).
|
||||
4. [Bootstrap](https://github.com/twbs/bootstrap).
|
9
utils/trace-visualizer/css/bootstrap.min.css
vendored
Normal file
9
utils/trace-visualizer/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
78
utils/trace-visualizer/css/d3-gantt.css
Normal file
78
utils/trace-visualizer/css/d3-gantt.css
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* d3-gantt.css by @serxa
|
||||
*/
|
||||
|
||||
.chart {
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
rect.zoom-panel {
|
||||
/*cursor: ew-resize;*/
|
||||
fill: none;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
.axis path,.axis line {
|
||||
fill: none;
|
||||
stroke: #000;
|
||||
shape-rendering: crispEdges;
|
||||
}
|
||||
|
||||
.axis.y {
|
||||
font-size: 16px;
|
||||
cursor: ns-resize;
|
||||
}
|
||||
|
||||
.axis.x {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#ruler {
|
||||
text-anchor: middle;
|
||||
alignment-baseline: before-edge;
|
||||
font-size: 16px;
|
||||
font-family: sans-serif;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.d3-tip {
|
||||
line-height: 1;
|
||||
font-weight: bold;
|
||||
padding: 12px;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #fff;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.d3-tip pre {
|
||||
font-weight: bold;
|
||||
padding: 12px;
|
||||
background: rgba(0, 0, 0, 0);
|
||||
color: #fff;
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
/* Style northward tooltips differently */
|
||||
.d3-tip.n:after {
|
||||
margin: -1px 0 0 0;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/* for arrowhead marker */
|
||||
#arrow {
|
||||
stroke-width:1;
|
||||
stroke-dasharray:0;
|
||||
}
|
||||
|
||||
.bar:hover {
|
||||
stroke-width: 1px;
|
||||
stroke: black;
|
||||
}
|
||||
|
||||
#errmsg {
|
||||
width: 95vw;
|
||||
margin: 0 auto;
|
||||
padding: 10px;
|
||||
}
|
118
utils/trace-visualizer/index.html
Normal file
118
utils/trace-visualizer/index.html
Normal file
@ -0,0 +1,118 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Trace Gantt</title>
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="css/d3-gantt.css">
|
||||
</head>
|
||||
<body>
|
||||
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="js/bootstrap.min.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="js/d3.v4.min.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="js/d3-tip-0.8.0-alpha.1.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="js/d3-gantt.js"></script>
|
||||
<div id="placeholder" class="chart-placeholder"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script language="javascript">
|
||||
var example_json = [
|
||||
{ t1: 100, t2: 200, band: "band1", color: "#888", text: "text1" },
|
||||
{ t1: 300, t2: 400, band: "band2", color: "#ff8", text: "text2" },
|
||||
{ t1: 100, t2: 400, band: "band3", color: "#888", text: "some very long text with a lot of letters in it" },
|
||||
{ t1: 300, t2: 400, band: "band1", color: "#8ff", text: "some_very_long_identifier_with_a_lot_of_letters_in_it" },
|
||||
{ t1: 500, t2: 800, band: "band2", color: "#f8f", text: "test\nif\nnew\nline\nworks\nhere?" }
|
||||
];
|
||||
|
||||
var chart = d3.gantt()
|
||||
.height(window.innerHeight - $("#placeholder")[0].getBoundingClientRect().y - window.scrollY)
|
||||
.selector("#placeholder");
|
||||
|
||||
var data = null;
|
||||
|
||||
// Error message popup
|
||||
$("<div id='errmsg'></div>").css({
|
||||
position: "absolute",
|
||||
display: "none",
|
||||
border: "1px solid #faa",
|
||||
padding: "2px",
|
||||
"background-color": "#fcc",
|
||||
opacity: 0.80
|
||||
}).appendTo("body");
|
||||
|
||||
function fetchData(dataurl, parser = x => x) {
|
||||
function onDataReceived(json, textStatus, xhr) {
|
||||
$("#errmsg").hide();
|
||||
data = parser(json);
|
||||
chart(data);
|
||||
}
|
||||
|
||||
function onDataError(xhr, error) {
|
||||
console.log(arguments);
|
||||
$("#errmsg").text("Fetch data error: " + error + (xhr.status == 200? xhr.responseText: ""))
|
||||
.css({bottom: "5px", left: "25%", width: "50%"})
|
||||
.fadeIn(200);
|
||||
}
|
||||
|
||||
if (dataurl) {
|
||||
$.ajax({
|
||||
url: dataurl,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (json, textStatus, xhr) { onDataReceived(json, textStatus, xhr); },
|
||||
error: onDataError
|
||||
});
|
||||
} else {
|
||||
onDataReceived(example_json, "textStatus", "xhr");
|
||||
}
|
||||
}
|
||||
|
||||
function parseClickHouseTrace(json) {
|
||||
let min_time_us = Number.MAX_VALUE;
|
||||
for (let i = 0; i < json.data.length; i++) {
|
||||
let span = json.data[i];
|
||||
min_time_us = Math.min(min_time_us, +span.start_time_us);
|
||||
}
|
||||
|
||||
let max_time_ms = 0;
|
||||
function convertTime(us) {
|
||||
let value = (us - min_time_us) / 1000;
|
||||
max_time_ms = Math.max(max_time_ms, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
function strHash(str) {
|
||||
var hash = 0;
|
||||
if (str.length === 0)
|
||||
return hash;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
if (hash < 0)
|
||||
hash = -hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
let result = [];
|
||||
for (let i = 0; i < json.data.length; i++) {
|
||||
let span = json.data[i];
|
||||
result.push({
|
||||
t1: convertTime(+span.start_time_us),
|
||||
t2: convertTime(+span.finish_time_us),
|
||||
band: Object.values(span.group).join(' '),
|
||||
color: d3.interpolateRainbow((strHash(span.color) % 256) / 256),
|
||||
text: span.operation_name
|
||||
});
|
||||
}
|
||||
|
||||
chart.timeDomain([0, max_time_ms]);
|
||||
return result;
|
||||
}
|
||||
|
||||
fetchData(); // do not fetch, just draw example_json w/o parsing
|
||||
//fetchData("your-traces.json" , parseClickHouseTrace);
|
||||
</script>
|
9
utils/trace-visualizer/js/bootstrap.min.js
vendored
Normal file
9
utils/trace-visualizer/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
485
utils/trace-visualizer/js/d3-gantt.js
vendored
Normal file
485
utils/trace-visualizer/js/d3-gantt.js
vendored
Normal file
@ -0,0 +1,485 @@
|
||||
/*
|
||||
* d3-gantt.js by @serxa
|
||||
* Based on https://github.com/ydb-platform/ydb/blob/stable-22-2/library/cpp/lwtrace/mon/static/js/d3-gantt.js
|
||||
*/
|
||||
d3.gantt = function() {
|
||||
function gantt(input_data) {
|
||||
data = input_data;
|
||||
|
||||
initAxis();
|
||||
|
||||
// create svg element
|
||||
svg = d3.select(selector)
|
||||
.append("svg")
|
||||
.attr("class", "chart")
|
||||
.attr("width", width + margin.left + margin.right)
|
||||
.attr("height", height + margin.top + margin.bottom)
|
||||
;
|
||||
|
||||
// create arrowhead marker
|
||||
defs = svg.append("defs");
|
||||
defs.append("marker")
|
||||
.attr("id", "arrow")
|
||||
.attr("viewBox", "0 -5 10 10")
|
||||
.attr("refX", 5)
|
||||
.attr("refY", 0)
|
||||
.attr("markerWidth", 4)
|
||||
.attr("markerHeight", 4)
|
||||
.attr("orient", "auto")
|
||||
.append("path")
|
||||
.attr("d", "M0,-5L10,0L0,5")
|
||||
.attr("class","arrowHead")
|
||||
;
|
||||
|
||||
zoom = d3.zoom()
|
||||
.scaleExtent([0.1, 1000])
|
||||
//.translateExtent([0, 0], [1000,0])
|
||||
.on("zoom", function() {
|
||||
if (tipShown != null) {
|
||||
tip.hide(tipShown);
|
||||
}
|
||||
var tr = d3.event.transform;
|
||||
xZoomed = tr.rescaleX(x);
|
||||
svg.select("g.x.axis").call(xAxis.scale(xZoomed));
|
||||
|
||||
var dy = d3.event.sourceEvent.screenY - zoom.startScreenY;
|
||||
var newScrollTop = documentBodyScrollTop() - dy;
|
||||
window.scrollTo(documentBodyScrollLeft(), newScrollTop);
|
||||
documentBodyScrollTop(newScrollTop);
|
||||
zoom.startScreenY = d3.event.sourceEvent.screenY;
|
||||
|
||||
zoomContainer1.attr("transform", "translate(" + tr.x + ",0) scale(" + tr.k + ",1)");
|
||||
zoomContainer2.attr("transform", "translate(" + tr.x + ",0) scale(" + tr.k + ",1)");
|
||||
|
||||
render();
|
||||
})
|
||||
.on("start", function() {
|
||||
zoom.startScreenY = d3.event.sourceEvent.screenY;
|
||||
})
|
||||
.on("end", function() {
|
||||
})
|
||||
;
|
||||
|
||||
svgChartContainer = svg.append('g')
|
||||
.attr("transform", "translate(" + margin.left + ", " + margin.top + ")")
|
||||
;
|
||||
svgChart = svgChartContainer.append("svg")
|
||||
.attr("top", 0)
|
||||
.attr("left", 0)
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.attr("viewBox", "0 0 " + width + " " + height)
|
||||
;
|
||||
|
||||
zoomContainer1 = svgChart.append("g");
|
||||
|
||||
zoomPanel = svgChart.append("rect")
|
||||
.attr("class", "zoom-panel")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.call(zoom)
|
||||
;
|
||||
|
||||
zoomContainer2 = svgChart.append("g");
|
||||
bandsSvg = zoomContainer2.append("g");
|
||||
|
||||
// tooltips for bands
|
||||
var maxTipHeight = 130;
|
||||
const tipDirection = d => y(d.band) - maxTipHeight < documentBodyScrollTop()? 's': 'n';
|
||||
tip = d3.tip()
|
||||
.attr("class", "d3-tip")
|
||||
.offset(function(d) {
|
||||
// compute x to return tip in chart region
|
||||
var t0 = (d.t1 + d.t2) / 2;
|
||||
var t1 = Math.min(Math.max(t0, xZoomed.invert(0)), xZoomed.invert(width));
|
||||
var dir = tipDirection(d);
|
||||
return [dir === 'n'? -10 : 10, xZoomed(t1) - xZoomed(t0)];
|
||||
})
|
||||
.direction(tipDirection)
|
||||
.html(d => "<pre>" + d.text + "</pre>")
|
||||
;
|
||||
|
||||
bandsSvg.call(tip);
|
||||
|
||||
render();
|
||||
|
||||
// container for non-zoomable elements
|
||||
fixedContainer = svg.append("g")
|
||||
.attr("transform", "translate(" + margin.left + ", " + margin.top + ")")
|
||||
;
|
||||
|
||||
// create x axis
|
||||
fixedContainer.append("g")
|
||||
.attr("class", "x axis")
|
||||
.attr("transform", "translate(0, " + (height - margin.top - margin.bottom) + ")")
|
||||
.transition()
|
||||
.call(xAxis)
|
||||
;
|
||||
|
||||
// create y axis
|
||||
fixedContainer.append("g")
|
||||
.attr("class", "y axis")
|
||||
.transition()
|
||||
.call(yAxis)
|
||||
;
|
||||
|
||||
// make y axis ticks draggable
|
||||
var ytickdrag = d3.drag()
|
||||
.on("drag", function(d) {
|
||||
var ypos = d3.event.y - margin.top;
|
||||
var index = Math.floor((ypos / y.step()));
|
||||
index = Math.min(Math.max(index, 0), this.initDomain.length - 1);
|
||||
if (index != this.curIndex) {
|
||||
var newDomain = [];
|
||||
for (var i = 0; i < this.initDomain.length; ++i) {
|
||||
newDomain.push(this.initDomain[i]);
|
||||
}
|
||||
newDomain.splice(this.initIndex, 1);
|
||||
newDomain.splice(index, 0, this.initDomain[this.initIndex]);
|
||||
|
||||
this.curIndex = index;
|
||||
this.curDomain = newDomain;
|
||||
y.domain(newDomain);
|
||||
|
||||
// rearange y scale and axis
|
||||
svg.select("g.y.axis").transition().call(yAxis);
|
||||
|
||||
// rearange other stuff
|
||||
render(-1, true);
|
||||
}
|
||||
})
|
||||
.on("start", function(d) {
|
||||
var ypos = d3.event.y - margin.top;
|
||||
this.initIndex = Math.floor((ypos / y.step()));
|
||||
this.initDomain = y.domain();
|
||||
})
|
||||
.on("end", function(d) {
|
||||
svg.select("g.y.axis").call(yAxis);
|
||||
})
|
||||
;
|
||||
svg.selectAll("g.y.axis .tick")
|
||||
.call(ytickdrag)
|
||||
;
|
||||
|
||||
// right margin
|
||||
var rmargin = fixedContainer.append("g")
|
||||
.attr("id", "right-margin")
|
||||
.attr("transform", "translate(" + width + ", 0)")
|
||||
;
|
||||
rmargin.append("rect")
|
||||
.attr("x", 0)
|
||||
.attr("y", 0)
|
||||
.attr("width", 1)
|
||||
.attr("height", height - margin.top - margin.bottom)
|
||||
;
|
||||
|
||||
// top margin
|
||||
var tmargin = fixedContainer.append("g")
|
||||
.attr("id", "top-margin")
|
||||
.attr("transform", "translate(0, 0)")
|
||||
;
|
||||
tmargin.append("rect")
|
||||
.attr("x", 0)
|
||||
.attr("y", 0)
|
||||
.attr("width", width)
|
||||
.attr("height", 1)
|
||||
;
|
||||
|
||||
// ruler
|
||||
ruler = fixedContainer.append("g")
|
||||
.attr("id", "ruler")
|
||||
.attr("transform", "translate(0, 0)")
|
||||
;
|
||||
ruler.append("rect")
|
||||
.attr("id", "ruler-line")
|
||||
.attr("x", 0)
|
||||
.attr("y", 0)
|
||||
.attr("width", "1")
|
||||
.attr("height", height - margin.top - margin.bottom + 8)
|
||||
;
|
||||
ruler.append("rect")
|
||||
.attr("id", "bgrect")
|
||||
.attr("x", 0)
|
||||
.attr("y", 0)
|
||||
.attr("width", 0)
|
||||
.attr("height", 0)
|
||||
.style("fill", "white")
|
||||
;
|
||||
ruler.append("text")
|
||||
.attr("x", 0)
|
||||
.attr("y", height - margin.top - margin.bottom + 16)
|
||||
.attr("dy", "0.71em")
|
||||
.text("0")
|
||||
;
|
||||
|
||||
svg.on('mousemove', function() {
|
||||
positionRuler(d3.event.pageX);
|
||||
});
|
||||
|
||||
// scroll handling
|
||||
window.onscroll = function myFunction() {
|
||||
documentBodyScrollLeft(document.body.scrollLeft);
|
||||
documentBodyScrollTop(document.body.scrollTop);
|
||||
var scroll = scrollParams();
|
||||
|
||||
svgChartContainer
|
||||
.attr("transform", "translate(" + margin.left
|
||||
+ ", " + (margin.top + scroll.y1) + ")");
|
||||
svgChart
|
||||
.attr("viewBox", "0 " + scroll.y1 + " " + width + " " + scroll.h)
|
||||
.attr("height", scroll.h);
|
||||
tmargin
|
||||
.attr("transform", "translate(0," + scroll.y1 + ")");
|
||||
fixedContainer.select(".x.axis")
|
||||
.attr("transform", "translate(0," + scroll.y2 + ")");
|
||||
rmargin.select("rect")
|
||||
.attr("y", scroll.y1)
|
||||
.attr("height", scroll.h);
|
||||
ruler.select("#ruler-line")
|
||||
.attr("y", scroll.y1)
|
||||
.attr("height", scroll.h);
|
||||
|
||||
positionRuler();
|
||||
}
|
||||
|
||||
// render axis
|
||||
svg.select("g.x.axis").call(xAxis);
|
||||
svg.select("g.y.axis").call(yAxis);
|
||||
|
||||
// update to initiale state
|
||||
window.onscroll(0);
|
||||
|
||||
return gantt;
|
||||
}
|
||||
|
||||
// private:
|
||||
|
||||
var keyFunction = function(d) {
|
||||
return d.t1.toString() + d.t2.toString() + d.band.toString();
|
||||
}
|
||||
|
||||
var bandTransform = function(d) {
|
||||
return "translate(" + x(d.t1) + "," + y(d.band) + ")";
|
||||
}
|
||||
|
||||
var xPixel = function(d) {
|
||||
return xZoomed.invert(1) - xZoomed.invert(0);
|
||||
}
|
||||
|
||||
var render = function(t0, smooth) {
|
||||
// Save/restore last t0 value
|
||||
if (!arguments.length || t0 == -1) {
|
||||
t0 = render.t0;
|
||||
}
|
||||
render.t0 = t0;
|
||||
smooth = smooth || false;
|
||||
|
||||
// Create rectangles for bands
|
||||
bands = bandsSvg.selectAll("rect.bar")
|
||||
.data(data, keyFunction);
|
||||
bands.exit().remove();
|
||||
bands.enter().append("rect")
|
||||
.attr("class", "bar")
|
||||
.attr("vector-effect", "non-scaling-stroke")
|
||||
.style("fill", d => d.color)
|
||||
.on('click', function(d) {
|
||||
if (tipShown != d) {
|
||||
tipShown = d;
|
||||
tip.show(d);
|
||||
} else {
|
||||
tipShown = null;
|
||||
tip.hide(d);
|
||||
}
|
||||
})
|
||||
.merge(bands)
|
||||
.transition().duration(smooth? 250: 0)
|
||||
.attr("y", 0)
|
||||
.attr("transform", bandTransform)
|
||||
.attr("height", y.bandwidth())
|
||||
.attr("width", d => Math.max(1*xPixel(), x(d.t2) - x(d.t1)))
|
||||
;
|
||||
|
||||
var emptyMarker = bandsSvg.selectAll("text")
|
||||
.data(data.length == 0? ["no data to show"]: []);
|
||||
emptyMarker.exit().remove();
|
||||
emptyMarker.enter().append("text")
|
||||
.text(d => d)
|
||||
;
|
||||
}
|
||||
|
||||
function initAxis() {
|
||||
x = d3.scaleLinear()
|
||||
.domain([timeDomainStart, timeDomainEnd])
|
||||
.range([0, width])
|
||||
//.clamp(true); // dosn't work with zoom/pan
|
||||
xZoomed = x;
|
||||
y = d3.scaleBand()
|
||||
.domain(Object.values(data).map(d => d.band).sort())
|
||||
.rangeRound([0, height - margin.top - margin.bottom])
|
||||
.padding(0.5);
|
||||
xAxis = d3.axisBottom()
|
||||
.scale(x)
|
||||
//.tickSubdivide(true)
|
||||
.tickSize(8)
|
||||
.tickPadding(8);
|
||||
yAxis = d3.axisLeft()
|
||||
.scale(y)
|
||||
.tickSize(0);
|
||||
}
|
||||
|
||||
// slow function wrapper
|
||||
var documentBodyScrollLeft = function(value) {
|
||||
if (!arguments.length) {
|
||||
if (documentBodyScrollLeft.value === undefined) {
|
||||
documentBodyScrollLeft.value = document.body.scrollLeft;
|
||||
}
|
||||
return documentBodyScrollLeft.value;
|
||||
} else {
|
||||
documentBodyScrollLeft.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// slow function wrapper
|
||||
var documentBodyScrollTop = function(value) {
|
||||
if (!arguments.length) {
|
||||
if (!documentBodyScrollTop.value === undefined) {
|
||||
documentBodyScrollTop.value = document.body.scrollTop;
|
||||
}
|
||||
return documentBodyScrollTop.value;
|
||||
} else {
|
||||
documentBodyScrollTop.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollParams = function() {
|
||||
var y1 = documentBodyScrollTop();
|
||||
var y2 = y1 + window.innerHeight - margin.footer;
|
||||
y2 = Math.min(y2, height - margin.top - margin.bottom);
|
||||
var h = y2 - y1;
|
||||
return {
|
||||
y1: y1,
|
||||
y2: y2,
|
||||
h: h
|
||||
};
|
||||
}
|
||||
|
||||
var posTextFormat = d3.format(".1f");
|
||||
|
||||
var positionRuler = function(pageX) {
|
||||
if (!arguments.length) {
|
||||
pageX = positionRuler.pageX || 0;
|
||||
} else {
|
||||
positionRuler.pageX = pageX;
|
||||
}
|
||||
|
||||
// x-coordinate
|
||||
if (!positionRuler.svgLeft) {
|
||||
positionRuler.svgLeft = svg.node().getBoundingClientRect().x;
|
||||
}
|
||||
|
||||
var xpos = pageX - margin.left + 1 - positionRuler.svgLeft;
|
||||
var tpos = xZoomed.invert(xpos);
|
||||
tpos = Math.min(Math.max(tpos, xZoomed.invert(0)), xZoomed.invert(width));
|
||||
ruler.attr("transform", "translate(" + xZoomed(tpos) + ", 0)");
|
||||
var posText = posTextFormat(tpos);
|
||||
|
||||
// scroll-related
|
||||
var scroll = scrollParams();
|
||||
|
||||
var text = ruler.select("text")
|
||||
.attr("y", scroll.y2 + 16)
|
||||
;
|
||||
|
||||
// getBBox() is very slow, so compute symbol width once
|
||||
var xpadding = 5;
|
||||
var ypadding = 5;
|
||||
if (!positionRuler.bbox) {
|
||||
positionRuler.bbox = text.node().getBBox();
|
||||
}
|
||||
|
||||
text.text(posText);
|
||||
var textWidth = 10 * posText.length;
|
||||
ruler.select("#bgrect")
|
||||
.attr("x", -textWidth/2 - xpadding)
|
||||
.attr("y", positionRuler.bbox.y - ypadding)
|
||||
.attr("width", textWidth + (xpadding*2))
|
||||
.attr("height", positionRuler.bbox.height + (ypadding*2))
|
||||
;
|
||||
|
||||
render(tpos);
|
||||
}
|
||||
|
||||
// public:
|
||||
|
||||
gantt.width = function(value) {
|
||||
if (!arguments.length)
|
||||
return width;
|
||||
width = +value;
|
||||
return gantt;
|
||||
}
|
||||
|
||||
gantt.height = function(value) {
|
||||
if (!arguments.length)
|
||||
return height;
|
||||
height = +value;
|
||||
return gantt;
|
||||
}
|
||||
|
||||
gantt.selector = function(value) {
|
||||
if (!arguments.length)
|
||||
return selector;
|
||||
selector = value;
|
||||
return gantt;
|
||||
}
|
||||
|
||||
gantt.timeDomain = function(value) {
|
||||
if (!arguments.length)
|
||||
return [timeDomainStart, timeDomainEnd];
|
||||
timeDomainStart = value[0];
|
||||
timeDomainEnd = value[1];
|
||||
return gantt;
|
||||
}
|
||||
|
||||
gantt.data = function() {
|
||||
return data;
|
||||
}
|
||||
|
||||
// constructor
|
||||
|
||||
// Config
|
||||
var margin = { top: 20, right: 40, bottom: 20, left: 200, footer: 100 },
|
||||
height = document.body.clientHeight - margin.top - margin.bottom - 5,
|
||||
width = document.body.clientWidth - margin.right - margin.left - 5,
|
||||
selector = 'body',
|
||||
timeDomainStart = 0,
|
||||
timeDomainEnd = 1000,
|
||||
scales = {};
|
||||
;
|
||||
|
||||
// View
|
||||
var x = null,
|
||||
xZoomed = null,
|
||||
y = null,
|
||||
xAxis = null,
|
||||
yAxis = null,
|
||||
svg = null,
|
||||
defs = null,
|
||||
svgChartContainer = null,
|
||||
svgChart = null,
|
||||
zoomPanel = null,
|
||||
zoomContainer1 = null,
|
||||
zoomContainer2 = null,
|
||||
fixedContainer = null,
|
||||
zoom = null,
|
||||
bandsSvg = null,
|
||||
bands = null,
|
||||
tip = null,
|
||||
tipShown = null,
|
||||
ruler = null
|
||||
;
|
||||
|
||||
// Model
|
||||
var data = null;
|
||||
|
||||
return gantt;
|
||||
}
|
352
utils/trace-visualizer/js/d3-tip-0.8.0-alpha.1.js
Normal file
352
utils/trace-visualizer/js/d3-tip-0.8.0-alpha.1.js
Normal file
@ -0,0 +1,352 @@
|
||||
/**
|
||||
* d3.tip
|
||||
* Copyright (c) 2013 Justin Palmer
|
||||
*
|
||||
* Tooltips for d3.js SVG visualizations
|
||||
*/
|
||||
// eslint-disable-next-line no-extra-semi
|
||||
;(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module with d3 as a dependency.
|
||||
define([
|
||||
'd3-collection',
|
||||
'd3-selection'
|
||||
], factory)
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
/* eslint-disable global-require */
|
||||
// CommonJS
|
||||
var d3Collection = require('d3-collection'),
|
||||
d3Selection = require('d3-selection')
|
||||
module.exports = factory(d3Collection, d3Selection)
|
||||
/* eslint-enable global-require */
|
||||
} else {
|
||||
// Browser global.
|
||||
var d3 = root.d3
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
root.d3.tip = factory(d3, d3)
|
||||
}
|
||||
}(this, function(d3Collection, d3Selection) {
|
||||
// Public - contructs a new tooltip
|
||||
//
|
||||
// Returns a tip
|
||||
return function() {
|
||||
var direction = d3TipDirection,
|
||||
offset = d3TipOffset,
|
||||
html = d3TipHTML,
|
||||
rootElement = document.body,
|
||||
node = initNode(),
|
||||
svg = null,
|
||||
point = null,
|
||||
target = null
|
||||
|
||||
function tip(vis) {
|
||||
svg = getSVGNode(vis)
|
||||
if (!svg) return
|
||||
point = svg.createSVGPoint()
|
||||
rootElement.appendChild(node)
|
||||
}
|
||||
|
||||
// Public - show the tooltip on the screen
|
||||
//
|
||||
// Returns a tip
|
||||
tip.show = function() {
|
||||
var args = Array.prototype.slice.call(arguments)
|
||||
if (args[args.length - 1] instanceof SVGElement) target = args.pop()
|
||||
|
||||
var content = html.apply(this, args),
|
||||
poffset = offset.apply(this, args),
|
||||
dir = direction.apply(this, args),
|
||||
nodel = getNodeEl(),
|
||||
i = directions.length,
|
||||
coords,
|
||||
scrollTop = document.documentElement.scrollTop ||
|
||||
rootElement.scrollTop,
|
||||
scrollLeft = document.documentElement.scrollLeft ||
|
||||
rootElement.scrollLeft
|
||||
|
||||
nodel.html(content)
|
||||
.style('opacity', 1).style('pointer-events', 'all')
|
||||
|
||||
while (i--) nodel.classed(directions[i], false)
|
||||
coords = directionCallbacks.get(dir).apply(this)
|
||||
nodel.classed(dir, true)
|
||||
.style('top', (coords.top + poffset[0]) + scrollTop + 'px')
|
||||
.style('left', (coords.left + poffset[1]) + scrollLeft + 'px')
|
||||
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public - hide the tooltip
|
||||
//
|
||||
// Returns a tip
|
||||
tip.hide = function() {
|
||||
var nodel = getNodeEl()
|
||||
nodel.style('opacity', 0).style('pointer-events', 'none')
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: Proxy attr calls to the d3 tip container.
|
||||
// Sets or gets attribute value.
|
||||
//
|
||||
// n - name of the attribute
|
||||
// v - value of the attribute
|
||||
//
|
||||
// Returns tip or attribute value
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
tip.attr = function(n, v) {
|
||||
if (arguments.length < 2 && typeof n === 'string') {
|
||||
return getNodeEl().attr(n)
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments)
|
||||
d3Selection.selection.prototype.attr.apply(getNodeEl(), args)
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: Proxy style calls to the d3 tip container.
|
||||
// Sets or gets a style value.
|
||||
//
|
||||
// n - name of the property
|
||||
// v - value of the property
|
||||
//
|
||||
// Returns tip or style property value
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
tip.style = function(n, v) {
|
||||
if (arguments.length < 2 && typeof n === 'string') {
|
||||
return getNodeEl().style(n)
|
||||
}
|
||||
|
||||
var args = Array.prototype.slice.call(arguments)
|
||||
d3Selection.selection.prototype.style.apply(getNodeEl(), args)
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: Set or get the direction of the tooltip
|
||||
//
|
||||
// v - One of n(north), s(south), e(east), or w(west), nw(northwest),
|
||||
// sw(southwest), ne(northeast) or se(southeast)
|
||||
//
|
||||
// Returns tip or direction
|
||||
tip.direction = function(v) {
|
||||
if (!arguments.length) return direction
|
||||
direction = v == null ? v : functor(v)
|
||||
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: Sets or gets the offset of the tip
|
||||
//
|
||||
// v - Array of [x, y] offset
|
||||
//
|
||||
// Returns offset or
|
||||
tip.offset = function(v) {
|
||||
if (!arguments.length) return offset
|
||||
offset = v == null ? v : functor(v)
|
||||
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: sets or gets the html value of the tooltip
|
||||
//
|
||||
// v - String value of the tip
|
||||
//
|
||||
// Returns html value or tip
|
||||
tip.html = function(v) {
|
||||
if (!arguments.length) return html
|
||||
html = v == null ? v : functor(v)
|
||||
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: sets or gets the root element anchor of the tooltip
|
||||
//
|
||||
// v - root element of the tooltip
|
||||
//
|
||||
// Returns root node of tip
|
||||
tip.rootElement = function(v) {
|
||||
if (!arguments.length) return rootElement
|
||||
rootElement = v == null ? v : functor(v)
|
||||
|
||||
return tip
|
||||
}
|
||||
|
||||
// Public: destroys the tooltip and removes it from the DOM
|
||||
//
|
||||
// Returns a tip
|
||||
tip.destroy = function() {
|
||||
if (node) {
|
||||
getNodeEl().remove()
|
||||
node = null
|
||||
}
|
||||
return tip
|
||||
}
|
||||
|
||||
function d3TipDirection() { return 'n' }
|
||||
function d3TipOffset() { return [0, 0] }
|
||||
function d3TipHTML() { return ' ' }
|
||||
|
||||
var directionCallbacks = d3Collection.map({
|
||||
n: directionNorth,
|
||||
s: directionSouth,
|
||||
e: directionEast,
|
||||
w: directionWest,
|
||||
nw: directionNorthWest,
|
||||
ne: directionNorthEast,
|
||||
sw: directionSouthWest,
|
||||
se: directionSouthEast
|
||||
}),
|
||||
directions = directionCallbacks.keys()
|
||||
|
||||
function directionNorth() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.n.y - node.offsetHeight,
|
||||
left: bbox.n.x - node.offsetWidth / 2
|
||||
}
|
||||
}
|
||||
|
||||
function directionSouth() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.s.y,
|
||||
left: bbox.s.x - node.offsetWidth / 2
|
||||
}
|
||||
}
|
||||
|
||||
function directionEast() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.e.y - node.offsetHeight / 2,
|
||||
left: bbox.e.x
|
||||
}
|
||||
}
|
||||
|
||||
function directionWest() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.w.y - node.offsetHeight / 2,
|
||||
left: bbox.w.x - node.offsetWidth
|
||||
}
|
||||
}
|
||||
|
||||
function directionNorthWest() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.nw.y - node.offsetHeight,
|
||||
left: bbox.nw.x - node.offsetWidth
|
||||
}
|
||||
}
|
||||
|
||||
function directionNorthEast() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.ne.y - node.offsetHeight,
|
||||
left: bbox.ne.x
|
||||
}
|
||||
}
|
||||
|
||||
function directionSouthWest() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.sw.y,
|
||||
left: bbox.sw.x - node.offsetWidth
|
||||
}
|
||||
}
|
||||
|
||||
function directionSouthEast() {
|
||||
var bbox = getScreenBBox()
|
||||
return {
|
||||
top: bbox.se.y,
|
||||
left: bbox.se.x
|
||||
}
|
||||
}
|
||||
|
||||
function initNode() {
|
||||
var div = d3Selection.select(document.createElement('div'))
|
||||
div
|
||||
.style('position', 'absolute')
|
||||
.style('top', 0)
|
||||
.style('opacity', 0)
|
||||
.style('pointer-events', 'none')
|
||||
.style('box-sizing', 'border-box')
|
||||
|
||||
return div.node()
|
||||
}
|
||||
|
||||
function getSVGNode(element) {
|
||||
var svgNode = element.node()
|
||||
if (!svgNode) return null
|
||||
if (svgNode.tagName.toLowerCase() === 'svg') return svgNode
|
||||
return svgNode.ownerSVGElement
|
||||
}
|
||||
|
||||
function getNodeEl() {
|
||||
if (node == null) {
|
||||
node = initNode()
|
||||
// re-add node to DOM
|
||||
rootElement.appendChild(node)
|
||||
}
|
||||
return d3Selection.select(node)
|
||||
}
|
||||
|
||||
// Private - gets the screen coordinates of a shape
|
||||
//
|
||||
// Given a shape on the screen, will return an SVGPoint for the directions
|
||||
// n(north), s(south), e(east), w(west), ne(northeast), se(southeast),
|
||||
// nw(northwest), sw(southwest).
|
||||
//
|
||||
// +-+-+
|
||||
// | |
|
||||
// + +
|
||||
// | |
|
||||
// +-+-+
|
||||
//
|
||||
// Returns an Object {n, s, e, w, nw, sw, ne, se}
|
||||
function getScreenBBox() {
|
||||
var targetel = target || d3Selection.event.target
|
||||
|
||||
while (targetel.getScreenCTM == null && targetel.parentNode == null) {
|
||||
targetel = targetel.parentNode
|
||||
}
|
||||
|
||||
var bbox = {},
|
||||
matrix = targetel.getScreenCTM(),
|
||||
tbbox = targetel.getBBox(),
|
||||
width = tbbox.width,
|
||||
height = tbbox.height,
|
||||
x = tbbox.x,
|
||||
y = tbbox.y
|
||||
|
||||
point.x = x
|
||||
point.y = y
|
||||
bbox.nw = point.matrixTransform(matrix)
|
||||
point.x += width
|
||||
bbox.ne = point.matrixTransform(matrix)
|
||||
point.y += height
|
||||
bbox.se = point.matrixTransform(matrix)
|
||||
point.x -= width
|
||||
bbox.sw = point.matrixTransform(matrix)
|
||||
point.y -= height / 2
|
||||
bbox.w = point.matrixTransform(matrix)
|
||||
point.x += width
|
||||
bbox.e = point.matrixTransform(matrix)
|
||||
point.x -= width / 2
|
||||
point.y -= height / 2
|
||||
bbox.n = point.matrixTransform(matrix)
|
||||
point.y += height
|
||||
bbox.s = point.matrixTransform(matrix)
|
||||
|
||||
return bbox
|
||||
}
|
||||
|
||||
// Private - replace D3JS 3.X d3.functor() function
|
||||
function functor(v) {
|
||||
return typeof v === 'function' ? v : function() {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
return tip
|
||||
}
|
||||
// eslint-disable-next-line semi
|
||||
}));
|
2
utils/trace-visualizer/js/d3.v4.min.js
vendored
Normal file
2
utils/trace-visualizer/js/d3.v4.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
5
utils/trace-visualizer/js/jquery.min.js
vendored
Normal file
5
utils/trace-visualizer/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user