Skip to content

Commit

Permalink
Merge pull request neoground#23 from W0CHP/master
Browse files Browse the repository at this point in the history
Use ordinal direction names for labels in my custom WindDir Charts
  • Loading branch information
seehase committed May 15, 2023
2 parents 3671357 + bda692b commit 9bfa6f3
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/graph_line_archive_config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ grid: {
position: 'back',
xaxis: {
lines: {
show: true
show: false
}
},
yaxis: {
Expand Down
2 changes: 1 addition & 1 deletion src/graph_line_config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ grid: {
position: 'back',
xaxis: {
lines: {
show: true
show: false
}
},
yaxis: {
Expand Down
39 changes: 33 additions & 6 deletions src/index.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,45 @@

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
9 changes: 8 additions & 1 deletion src/js.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@
},
},
}
</script>

## Ordinals conversion for W0CHP's custom WindDir Charts:
function getOrdinalDirection(degrees) {
var sectors = ['North', 'NE', 'East', 'SE', 'South', 'SW', 'West', 'NW'];
var index = Math.round(degrees / (360 / sectors.length));
return sectors[index % sectors.length];
}
</script>
39 changes: 33 additions & 6 deletions src/month-%Y-%m.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,45 @@ new ApexCharts(document.querySelector('#$id'), {

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
39 changes: 33 additions & 6 deletions src/month.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,45 @@

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
39 changes: 33 additions & 6 deletions src/week.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,45 @@

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
39 changes: 33 additions & 6 deletions src/year-%Y.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,45 @@ new ApexCharts(document.querySelector('#$id'), {

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
39 changes: 33 additions & 6 deletions src/year.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,45 @@ new ApexCharts(document.querySelector('#$id'), {

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down
39 changes: 33 additions & 6 deletions src/yesterday.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,45 @@ half_length4 = Math.ceil(series4data.length / 2);

new ApexCharts(document.querySelector('#$id'), {
...graph_${type}_config,
yaxis: {
#if $name == "windDir"
#if $name == "windDir"
yaxis: {
max: 360,
min: 0,
type: 'datetime',
tickAmount: 8,
#end if
trim: false,
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
tickAmount: 8,
rotateAlways: false,
hideOverlappingLabels: true,
showDuplicates: false,
trim: false,
formatter: function(val, timestamp) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction;
}
},
},
},
tooltip: {
enabled: true,
y: {
formatter: function (val) {
var degrees = Number(val);
var direction = getOrdinalDirection(degrees);
return direction + ' (' + degrees.toFixed(0) + '°)';
}
},
},
#else
yaxis: {
labels: {
formatter: function (val) {
return formatNumber(val, "$getVar('unit.format.' + name)") + "$getVar('unit.label.' + name)";
}
},
},
#end if
series: [
{
name: "$getVar('obs.label.' + series1)",
Expand Down

0 comments on commit 9bfa6f3

Please sign in to comment.