forked from ps249eph7/Nginx
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
20 KiB
1 line
20 KiB
7 months ago
|
/*** ______ ___* / ____/___ / | _____________ __________* / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/* / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ )* \____/\____/_/ |_\___/\___/\___/____/____/** The MIT License (MIT)* Copyright (c) 2009-2018 Gerardo Orellana <hello @ goaccess.io>*/'use strict';function truncate(text, width) {text.each(function () {var parent = this.parentNode, $d3parent = d3.select(parent);var gw = $d3parent.node().getBBox();var x = (Math.min(gw.width, width) / 2) * -1;if ('svg' == parent.nodeName) {$d3parent.attr('width', width).attr('x', x);}else {$d3parent.insert('svg', function () {return this;}.bind(this)).attr('class', 'wrap-text').attr('width', width).attr('x', x).append(function () {return this;}.bind(this));}});}function AreaChart(dualYaxis) {var opts = {};var margin = {top : 20,right : 50,bottom : 40,left : 50,},height = 170,nTicks = 10,padding = 10,width = 760;var labels = { x: 'Unnamed', y0: 'Unnamed', y1: 'Unnamed' };var format = { x: null, y0: null, y1: null};var xValue = function (d) {return d[0];},yValue0 = function (d) {return d[1];},yValue1 = function (d) {return d[2];};var xScale = d3.scale.ordinal();var yScale0 = d3.scale.linear().nice();var yScale1 = d3.scale.linear().nice();var xAxis = d3.svg.axis().scale(xScale).orient('bottom').tickFormat(function (d) {if (format.x)return GoAccess.Util.fmtValue(d, format.x);return d;});var yAxis0 = d3.svg.axis().scale(yScale0).orient('left').tickFormat(function (d) {return d3.format('.2s')(d);});var yAxis1 = d3.svg.axis().scale(yScale1).orient('right').tickFormat(function (d) {if (format.y1)return GoAccess.Util.fmtValue(d, format.y1);return d3.format('.2s')(d);});var xGrid = d3.svg.axis().scale(xScale).orient('bottom');var yGrid = d3.svg.axis().scale(yScale0).orient('left');var area0 = d3.svg.area().interpolate('cardinal').x(X).y(Y0);var area1 = d3.svg.area().interpolate('cardinal').x(X).y(Y1);var line0 = d3.svg.line().interpolate('cardinal').x(X).y(Y0);var line1 = d3.svg.line().interpolate('cardinal').x(X).y(Y1);function X(d) {return xScale(d[0]);}function Y0(d) {return yScale0(d[1]);}function Y1(d) {return yScale1(d[2]);}function innerW() {return width - margin.left - margin.right;}function innerH() {return height - margin.top - margin.bottom;}function getXTicks(data) {if (data.length < nTicks)return xScale.domain();return d3.range(0, data.length, Math.ceil(data.length / nTicks)).map(function (d) {return xScale.domain()[d];});}function getYTicks(scale) {var domain = scale.domain();return d3.range(domain[0], domain[1], Math.ceil(domain[1] / nTicks));}function mapData(data) {var _datum = function (d, i) {var datum = [xValue.call(data, d, i), yValue0.call(data, d, i)];dualYaxis && datum.push(yValue1.call(data, d, i));return datum;};return data.map(function (d, i) {return _datum(d, i);});}function updateScales(data) {xScale.domain(data.map(function (d) {return d[0];})).rangePoints([0, innerW()], 1);yScale0.domain([0, d3.max(data, function (d) {return d[1];})]).range([innerH(), 0]);dualYaxis && yScale1.domain([0, d3.max(data, function (d) {return d[2];})]).range([innerH(), 0]);}function toggleOpacity(ele, op) {d3.select(ele.parentNode).selectAll('.' + (ele.getAttribute('data-yaxis') == 'y0' ? 'y1' : 'y0')).attr('style', op);}function setLegendLabels(svg) {var rect = svg.selectAll('rect.legend.y0').data([null]);rect.enter().append('rect').attr('class', 'legend y0').attr('data-yaxis', 'y0').on('mousemove', function (d, i) { toggleOpacity(this, 'opacity:0.1'); }).on('mouseleave', function (d, i) { toggleOpacity(this, null); }).attr('y', (height - 15));rect.attr('x', (width / 2) - 100);var text = svg.selectAll('text.legend.y0').data([null]);text.enter().append('text').attr('class', 'legend y0').attr('data-yaxis', 'y0').on('mousemove', function (d, i) { toggleOpacity(this, 'opacity:0.1'); }).on('mouseleave', function (d, i) { toggleOpacity(this, null); }).attr('y', (height - 6));text.attr('x', (width / 2) - 85).text(labels.y0);if (!dualYaxis)return;rect = svg.selectAll('rect.legend.y1').data([null]);rect.enter().append('rect').attr(
|