baseddata.io/static/js/chart-params.js

140 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2024-08-08 14:28:01 +01:00
const fontScale = 0.8;
2024-08-01 14:06:16 +01:00
2024-08-08 11:53:39 +01:00
const backgroundColor = "#f9f9f9";
const tooltipBgColor = "#e7e7f5";
const textColor = "#373841";
const textStyleMain = {
fontFamily: "sans-serif",
fontSize: 12 * fontScale,
color: textColor,
};
const tooltip = {
borderColor: textColor,
backgroundColor: tooltipBgColor,
order: "seriesDesc",
textStyle: textStyleMain,
trigger: "axis",
};
2024-08-01 14:06:16 +01:00
const toolboxParams = {
2024-08-09 00:07:23 +01:00
itemSize: 16 * fontScale,
2024-08-01 14:06:16 +01:00
showTitle: true,
top: "-1%",
right: "20%",
iconStyle: {
2024-08-08 11:53:39 +01:00
borderColor: textColor,
2024-08-01 14:06:16 +01:00
borderWidth: 2,
},
feature: {
dataZoom: {
yAxisIndex: "none",
},
2024-08-15 15:00:44 +01:00
dataView: {},
2024-08-01 14:06:16 +01:00
saveAsImage: {
pixelRatio: 2,
},
},
};
const axisLabel = {
fontSize: 12 * fontScale,
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
margin: 10,
};
const axisLine = {
show: true,
lineStyle: {
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
width: 2,
},
};
const axisTick = { show: true };
const grid = {
bottom: 30,
top: 10,
left: 15,
containLabel: true,
};
const yaxisTextStyle = {
fontSize: 12 * fontScale,
padding: [0, 0, 10, 0],
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
};
const yaxisTextStyle2 = {
fontSize: 12 * fontScale,
padding: [50, 0, 0, 0],
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
};
2024-08-15 15:00:44 +01:00
function dataZoom() {
2024-08-01 14:06:16 +01:00
const dataZoom = [
{
2024-08-15 15:00:44 +01:00
type: "inside",
2024-08-01 14:06:16 +01:00
},
];
return dataZoom;
}
function nFormatter(value, digits) {
const lookup = [
{ value: 1, symbol: "" },
{ value: 1e3, symbol: "k" },
{ value: 1e6, symbol: "M" },
{ value: 1e9, symbol: "G" },
{ value: 1e12, symbol: "T" },
{ value: 1e15, symbol: "P" },
{ value: 1e18, symbol: "E" },
];
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
const item = lookup
.slice()
.reverse()
.find((item) => value >= item.value);
return item
? (value / item.value).toFixed(digits).replace(rx, "$1") + item.symbol
: "0";
}
2024-08-14 19:48:58 +01:00
function periodDropdown(periods, defaultIndex = 0) {
const modifiers = document.getElementById("chart-modifiers");
const dropdownContainer = document.createElement("div");
const dropdown = document.createElement("select");
const textNode = document.createTextNode("Select period: ");
dropdownContainer.id = "dropdown-container";
dropdown.id = "select-period-dropdown";
dropdownContainer.appendChild(textNode);
dropdownContainer.appendChild(dropdown);
modifiers.appendChild(dropdownContainer);
periods.forEach((period, index) => {
const option = document.createElement("option");
if (index === defaultIndex) {
option.selected = true;
}
option.value = period;
option.textContent = period;
dropdown.appendChild(option);
});
}
function getPeriodFromDropdown() {
let dropdown = document.getElementById("select-period-dropdown");
let selectedIndex = dropdown.selectedIndex;
return dropdown.options[selectedIndex].value;
}
2024-08-06 12:03:42 +01:00
window.addEventListener("resize", function () {
2024-08-01 14:06:16 +01:00
if (myChart != null && myChart != undefined) {
myChart.resize();
}
});