var meteoCharts = {}; var meteoCompassLabels = {0: 'S', 90: 'V', 180: 'J', 270: 'Z', 360: 'S'}; var meteoRangeMin = 1795561200000; var meteoRangeMax = 1795579466000; function meteoFormatTime(ms) { return moment(ms).format('HH:mm'); } function meteoFormatDateTime(ms) { return moment(ms).format('DD.MM., HH:mm'); } function meteoComputeExtremes(points) { var minPoint = null, maxPoint = null; for (var i = 0; i < points.length; i++) { var p = points[i]; if (p.y === null || p.y === undefined) continue; if (!minPoint || p.y < minPoint.y) minPoint = p; if (!maxPoint || p.y > maxPoint.y) maxPoint = p; } return (minPoint || maxPoint) ? {min: minPoint, max: maxPoint} : null; } function meteoExtremeType(extremes, p) { if (!extremes || !p) return null; if (extremes.max && p.x === extremes.max.x && p.y === extremes.max.y) return 'max'; if (extremes.min && p.x === extremes.min.x && p.y === extremes.min.y) return 'min'; return null; } function meteoBuildDataset(spec) { var extremes = spec.highlightExtremes ? meteoComputeExtremes(spec.points) : null; var baseRadius = spec.pointRadius !== undefined ? spec.pointRadius : 0; var baseHoverRadius = baseRadius || 3; return { label: spec.label, data: spec.points, borderColor: spec.color, backgroundColor: spec.color, borderWidth: 2, tension: 0.15, fill: false, spanGaps: true, showLine: spec.showLine !== false, meteoUnit: spec.unit || '', meteoTooltipMode: spec.tooltipMode || 'default', meteoExtremes: extremes, pointRadius: function(context) { return meteoExtremeType(extremes, context.raw) ? Math.max(baseRadius, 5) : baseRadius; }, pointHoverRadius: function(context) { return meteoExtremeType(extremes, context.raw) ? Math.max(baseHoverRadius, 7) : baseHoverRadius; }, pointBackgroundColor: spec.color, pointBorderColor: '#ffffff', pointBorderWidth: function(context) { return meteoExtremeType(extremes, context.raw) ? 2 : 0; } }; } function buildMeteoChart(canvasId, resetButtonId, specs, extraOptions) { var canvas = document.getElementById(canvasId); if (!canvas || typeof Chart === 'undefined' || !specs.length) { return; } extraOptions = extraOptions || {}; var yScale = {title: {display: !!extraOptions.yLabel, text: extraOptions.yLabel || ''}}; if (extraOptions.yMin !== undefined) yScale.min = extraOptions.yMin; if (extraOptions.yMax !== undefined) yScale.max = extraOptions.yMax; if (extraOptions.yMode === 'compass') { yScale.min = 0; yScale.max = 360; yScale.ticks = { stepSize: 90, callback: function(value) { return meteoCompassLabels[value] !== undefined ? meteoCompassLabels[value] : value; } }; } meteoCharts[canvasId] = new Chart(canvas.getContext('2d'), { type: 'line', data: {datasets: specs.map(meteoBuildDataset)}, options: { responsive: true, maintainAspectRatio: false, animation: false, interaction: {mode: 'nearest', axis: 'x', intersect: false}, scales: { x: { type: 'linear', min: meteoRangeMin, max: meteoRangeMax, ticks: {maxTicksLimit: 8, callback: meteoFormatTime} }, y: yScale }, plugins: { legend: {display: true, position: 'top'}, tooltip: { callbacks: { title: function(items) { return items.length ? meteoFormatDateTime(items[0].parsed.x) : ''; }, label: function(context) { var ds = context.dataset; if (ds.meteoTooltipMode === 'windDirection') { return meteo_wind_direction_name(context.parsed.y); } var extremeType = meteoExtremeType(ds.meteoExtremes, context.raw); var suffix = extremeType === 'max' ? ' (dnešné maximum)' : (extremeType === 'min' ? ' (dnešné minimum)' : ''); return ds.label + ': ' + context.parsed.y + ds.meteoUnit + suffix; } } }, zoom: { pan: {enabled: true, mode: 'x'}, zoom: {wheel: {enabled: true}, pinch: {enabled: true}, mode: 'x'}, limits: {x: {min: meteoRangeMin, max: meteoRangeMax}} } } } }); var resetButton = document.getElementById(resetButtonId); if (resetButton) { resetButton.addEventListener('click', function() { meteoCharts[canvasId].resetZoom(); }); } } $(document).ready(function() { buildMeteoChart('chart-temperature-canvas', 'chart-temperature-reset', [{"label":"Teplota (°C)","color":"#d6212a","points":[{"x":1795561200000,"y":-0.9},{"x":1795561260000,"y":-0.9},{"x":1795561320000,"y":-0.9},{"x":1795561380000,"y":-0.9},{"x":1795561440000,"y":-0.9},{"x":1795561500000,"y":-0.9},{"x":1795561560000,"y":-0.9},{"x":1795561620000,"y":-0.9},{"x":1795561680000,"y":-0.9},{"x":1795561740000,"y":-0.9},{"x":1795561800000,"y":-0.9},{"x":1795561860000,"y":-0.9},{"x":1795561920000,"y":-0.9},{"x":1795561980000,"y":-0.9},{"x":1795562040000,"y":-0.9},{"x":1795562100000,"y":-0.9},{"x":1795562160000,"y":-0.9},{"x":1795562220000,"y":-0.9},{"x":1795562280000,"y":-0.9},{"x":1795562340000,"y":-0.9},{"x":1795562400000,"y":-0.9},{"x":1795562460000,"y":-0.9},{"x":1795562520000,"y":-0.9},{"x":1795562580000,"y":-0.9},{"x":1795562640000,"y":-0.9},{"x":1795562700000,"y":-0.9},{"x":1795562760000,"y":-0.9},{"x":1795562820000,"y":-0.9},{"x":1795562880000,"y":-0.9},{"x":1795562940000,"y":-0.9},{"x":1795563000000,"y":-1},{"x":1795563060000,"y":-1},{"x":1795563120000,"y":-1},{"x":1795563180000,"y":-1},{"x":1795563240000,"y":-1},{"x":1795563300000,"y":-1},{"x":1795563360000,"y":-1},{"x":1795563420000,"y":-1},{"x":1795563480000,"y":-1},{"x":1795563540000,"y":-1},{"x":1795563900000,"y":-1.1},{"x":1795563960000,"y":-1.1},{"x":1795564020000,"y":-1.2},{"x":1795564080000,"y":-1.2},{"x":1795564140000,"y":-1.2},{"x":1795564200000,"y":-1.2},{"x":1795564260000,"y":-1.2},{"x":1795564320000,"y":-1.2},{"x":1795564380000,"y":-1.2},{"x":1795564440000,"y":-1.3},{"x":1795564500000,"y":-1.3},{"x":1795564560000,"y":-1.3},{"x":1795564620000,"y":-1.3},{"x":1795564680000,"y":-1.3},{"x":1795564740000,"y":-1.3},{"x":1795564800000,"y":-1.3},{"x":1795564860000,"y":-1.3},{"x":1795564920000,"y":-1.4},{"x":1795564980000,"y":-1.4},{"x":1795565040000,"y":-1.4},{"x":1795565100000,"y":-1.4},{"x":1795565160000,"y":-1.4},{"x":1795565220000,"y":-1.4},{"x":1795565280000,"y":-1.4},{"x":1795565340000,"y":-1.4},{"x":1795565400000,"y":-1.4},{"x":1795565460000,"y":-1.4},{"x":1795565520000,"y":-1.4},{"x":1795565580000,"y":-1.4},{"x":1795565640000,"y":-1.4},{"x":1795565700000,"y":-1.4},{"x":1795565760000,"y":-1.4},{"x":1795565820000,"y":-1.4},{"x":1795565880000,"y":-1.4},{"x":1795565940000,"y":-1.4},{"x":1795566000000,"y":-1.4},{"x":1795566060000,"y":-1.4},{"x":1795566120000,"y":-1.4},{"x":1795566180000,"y":-1.4},{"x":1795566240000,"y":-1.4},{"x":1795566300000,"y":-1.4},{"x":1795566360000,"y":-1.4},{"x":1795566420000,"y":-1.4},{"x":1795566480000,"y":-1.4},{"x":1795566540000,"y":-1.4},{"x":1795566600000,"y":-1.4},{"x":1795566660000,"y":-1.4},{"x":1795566720000,"y":-1.4},{"x":1795566780000,"y":-1.3},{"x":1795566840000,"y":-1.3},{"x":1795566900000,"y":-1.3},{"x":1795566960000,"y":-1.3},{"x":1795567020000,"y":-1.3},{"x":1795567080000,"y":-1.3},{"x":1795567140000,"y":-1.3},{"x":1795567500000,"y":-1.3},{"x":1795567560000,"y":-1.3},{"x":1795567620000,"y":-1.3},{"x":1795567680000,"y":-1.3},{"x":1795567740000,"y":-1.4},{"x":1795567800000,"y":-1.4},{"x":1795567860000,"y":-1.4},{"x":1795567920000,"y":-1.4},{"x":1795567980000,"y":-1.4},{"x":1795568040000,"y":-1.4},{"x":1795568100000,"y":-1.4},{"x":1795568160000,"y":-1.4},{"x":1795568220000,"y":-1.3},{"x":1795568280000,"y":-1.3},{"x":1795568340000,"y":-1.3},{"x":1795568400000,"y":-1.3},{"x":1795568460000,"y":-1.3},{"x":1795568520000,"y":-1.3},{"x":1795568580000,"y":-1.3},{"x":1795568640000,"y":-1.3},{"x":1795568700000,"y":-1.3},{"x":1795568760000,"y":-1.3},{"x":1795568820000,"y":-1.3},{"x":1795568880000,"y":-1.3},{"x":1795568940000,"y":-1.3},{"x":1795569000000,"y":-1.3},{"x":1795569060000,"y":-1.3},{"x":1795569120000,"y":-1.3},{"x":1795569180000,"y":-1.3},{"x":1795569240000,"y":-1.3},{"x":1795569300000,"y":-1.3},{"x":1795569360000,"y":-1.3},{"x":1795569420000,"y":-1.3},{"x":1795569480000,"y":-1.3},{"x":1795569540000,"y":-1.3},{"x":1795569600000,"y":-1.2},{"x":1795569660000,"y":-1.2},{"x":1795569720000,"y":-1.2},{"x":1795569780000,"y":-1.2},{"x":1795569840000,"y":-1.2},{"x":1795569900000,"y":-1.2},{"x":1795569960000,"y":-1.2},{"x":1795570020000,"y":-1.3},{"x":1795570080000,"y":-1.3},{"x":1795570140000,"y":-1.3},{"x":1795570200000,"y":-1.3},{"x":1795570260000,"y":-1.3},{"x":1795570320000,"y":-1.3},{"x":1795570380000,"y":-1.3},{"x":1795570440000,"y":-1.3},{"x":1795570500000,"y":-1.4},{"x":1795570560000,"y":-1.4},{"x":1795570620000,"y":-1.4},{"x":1795570680000,"y":-1.4},{"x":1795570740000,"y":-1.4},{"x":1795571100000,"y":-1.4},{"x":1795571160000,"y":-1.5},{"x":1795571220000,"y":-1.5},{"x":1795571280000,"y":-1.5},{"x":1795571340000,"y":-1.5},{"x":1795571400000,"y":-1.5},{"x":1795571460000,"y":-1.6},{"x":1795571520000,"y":-1.6},{"x":1795571580000,"y":-1.6},{"x":1795571640000,"y":-1.6},{"x":1795571700000,"y":-1.6},{"x":1795571760000,"y":-1.6},{"x":1795571820000,"y":-1.7},{"x":1795571880000,"y":-1.7},{"x":1795571940000,"y":-1.7},{"x":1795572000000,"y":-1.8},{"x":1795572060000,"y":-1.8},{"x":1795572120000,"y":-2},{"x":1795572180000,"y":-2.1},{"x":1795572240000,"y":-2.1},{"x":1795572300000,"y":-2.1},{"x":1795572360000,"y":-2.2},{"x":1795572420000,"y":-2.3},{"x":1795572480000,"y":-2.3},{"x":1795572540000,"y":-2.3},{"x":1795572600000,"y":-2.4},{"x":1795572660000,"y":-2.4},{"x":1795572720000,"y":-2.4},{"x":1795572780000,"y":-2.4},{"x":1795572840000,"y":-2.4},{"x":1795572900000,"y":-2.4},{"x":1795572960000,"y":-2.5},{"x":1795573020000,"y":-2.6},{"x":1795573080000,"y":-2.7},{"x":1795573140000,"y":-2.8},{"x":1795573200000,"y":-2.8},{"x":1795573260000,"y":-2.8},{"x":1795573320000,"y":-2.8},{"x":1795573380000,"y":-2.9},{"x":1795573440000,"y":-2.9},{"x":1795573500000,"y":-2.9},{"x":1795573560000,"y":-3},{"x":1795573620000,"y":-3},{"x":1795573680000,"y":-3.1},{"x":1795573740000,"y":-3.2},{"x":1795573800000,"y":-3.2},{"x":1795573860000,"y":-3.3},{"x":1795573920000,"y":-3.3},{"x":1795573980000,"y":-3.4},{"x":1795574040000,"y":-3.4},{"x":1795574100000,"y":-3.4},{"x":1795574160000,"y":-3.4},{"x":1795574220000,"y":-3.4},{"x":1795574280000,"y":-3.5},{"x":1795574340000,"y":-3.5},{"x":1795574700000,"y":-3.6},{"x":1795574760000,"y":-3.7},{"x":1795574820000,"y":-3.7},{"x":1795574880000,"y":-3.7},{"x":1795574940000,"y":-3.7},{"x":1795575000000,"y":-3.7},{"x":1795575060000,"y":-3.7},{"x":1795575120000,"y":-3.6},{"x":1795575180000,"y":-3.7},{"x":1795575240000,"y":-3.7}],"highlightExtremes":true,"unit":" °C"},{"label":"Rosný bod (°C)","color":"#5b9f4a","points":[],"highlightExtremes":false,"unit":" °C"}], {"yLabel":"\u00b0C"}); }); $(document).ready(function() { buildMeteoChart('chart-rain-canvas', 'chart-rain-reset', [{"label":"Zrážky (mm)","color":"#008fbf","points":[{"x":1795561200000,"y":0},{"x":1795561260000,"y":0},{"x":1795561320000,"y":0},{"x":1795561380000,"y":0},{"x":1795561440000,"y":0},{"x":1795561500000,"y":0},{"x":1795561560000,"y":0},{"x":1795561620000,"y":0},{"x":1795561680000,"y":0},{"x":1795561740000,"y":0},{"x":1795561800000,"y":0},{"x":1795561860000,"y":0},{"x":1795561920000,"y":0},{"x":1795561980000,"y":0},{"x":1795562040000,"y":0},{"x":1795562100000,"y":0},{"x":1795562160000,"y":0},{"x":1795562220000,"y":0},{"x":1795562280000,"y":0},{"x":1795562340000,"y":0},{"x":1795562400000,"y":0},{"x":1795562460000,"y":0},{"x":1795562520000,"y":0},{"x":1795562580000,"y":0},{"x":1795562640000,"y":0},{"x":1795562700000,"y":0},{"x":1795562760000,"y":0},{"x":1795562820000,"y":0},{"x":1795562880000,"y":0},{"x":1795562940000,"y":0},{"x":1795563000000,"y":0},{"x":1795563060000,"y":0},{"x":1795563120000,"y":0},{"x":1795563180000,"y":0},{"x":1795563240000,"y":0},{"x":1795563300000,"y":0},{"x":1795563360000,"y":0},{"x":1795563420000,"y":0},{"x":1795563480000,"y":0},{"x":1795563540000,"y":0},{"x":1795563900000,"y":0},{"x":1795563960000,"y":0},{"x":1795564020000,"y":0},{"x":1795564080000,"y":0},{"x":1795564140000,"y":0},{"x":1795564200000,"y":0},{"x":1795564260000,"y":0},{"x":1795564320000,"y":0},{"x":1795564380000,"y":0},{"x":1795564440000,"y":0},{"x":1795564500000,"y":0},{"x":1795564560000,"y":0},{"x":1795564620000,"y":0},{"x":1795564680000,"y":0},{"x":1795564740000,"y":0},{"x":1795564800000,"y":0},{"x":1795564860000,"y":0},{"x":1795564920000,"y":0},{"x":1795564980000,"y":0},{"x":1795565040000,"y":0},{"x":1795565100000,"y":0},{"x":1795565160000,"y":0},{"x":1795565220000,"y":0},{"x":1795565280000,"y":0},{"x":1795565340000,"y":0},{"x":1795565400000,"y":0},{"x":1795565460000,"y":0},{"x":1795565520000,"y":0},{"x":1795565580000,"y":0},{"x":1795565640000,"y":0},{"x":1795565700000,"y":0},{"x":1795565760000,"y":0},{"x":1795565820000,"y":0},{"x":1795565880000,"y":0},{"x":1795565940000,"y":0},{"x":1795566000000,"y":0},{"x":1795566060000,"y":0},{"x":1795566120000,"y":0},{"x":1795566180000,"y":0},{"x":1795566240000,"y":0},{"x":1795566300000,"y":0},{"x":1795566360000,"y":0},{"x":1795566420000,"y":0},{"x":1795566480000,"y":0},{"x":1795566540000,"y":0},{"x":1795566600000,"y":0},{"x":1795566660000,"y":0},{"x":1795566720000,"y":0},{"x":1795566780000,"y":0},{"x":1795566840000,"y":0},{"x":1795566900000,"y":0},{"x":1795566960000,"y":0},{"x":1795567020000,"y":0},{"x":1795567080000,"y":0},{"x":1795567140000,"y":0},{"x":1795567500000,"y":0},{"x":1795567560000,"y":0},{"x":1795567620000,"y":0},{"x":1795567680000,"y":0},{"x":1795567740000,"y":0},{"x":1795567800000,"y":0},{"x":1795567860000,"y":0},{"x":1795567920000,"y":0},{"x":1795567980000,"y":0},{"x":1795568040000,"y":0},{"x":1795568100000,"y":0},{"x":1795568160000,"y":0},{"x":1795568220000,"y":0},{"x":1795568280000,"y":0},{"x":1795568340000,"y":0},{"x":1795568400000,"y":0},{"x":1795568460000,"y":0},{"x":1795568520000,"y":0},{"x":1795568580000,"y":0},{"x":1795568640000,"y":0},{"x":1795568700000,"y":0},{"x":1795568760000,"y":0},{"x":1795568820000,"y":0},{"x":1795568880000,"y":0},{"x":1795568940000,"y":0},{"x":1795569000000,"y":0},{"x":1795569060000,"y":0},{"x":1795569120000,"y":0},{"x":1795569180000,"y":0},{"x":1795569240000,"y":0},{"x":1795569300000,"y":0},{"x":1795569360000,"y":0},{"x":1795569420000,"y":0},{"x":1795569480000,"y":0},{"x":1795569540000,"y":0},{"x":1795569600000,"y":0},{"x":1795569660000,"y":0},{"x":1795569720000,"y":0},{"x":1795569780000,"y":0},{"x":1795569840000,"y":0},{"x":1795569900000,"y":0},{"x":1795569960000,"y":0},{"x":1795570020000,"y":0},{"x":1795570080000,"y":0},{"x":1795570140000,"y":0},{"x":1795570200000,"y":0},{"x":1795570260000,"y":0},{"x":1795570320000,"y":0},{"x":1795570380000,"y":0},{"x":1795570440000,"y":0},{"x":1795570500000,"y":0},{"x":1795570560000,"y":0},{"x":1795570620000,"y":0},{"x":1795570680000,"y":0},{"x":1795570740000,"y":0},{"x":1795571100000,"y":0},{"x":1795571160000,"y":0},{"x":1795571220000,"y":0},{"x":1795571280000,"y":0},{"x":1795571340000,"y":0},{"x":1795571400000,"y":0},{"x":1795571460000,"y":0},{"x":1795571520000,"y":0},{"x":1795571580000,"y":0},{"x":1795571640000,"y":0},{"x":1795571700000,"y":0},{"x":1795571760000,"y":0},{"x":1795571820000,"y":0},{"x":1795571880000,"y":0},{"x":1795571940000,"y":0},{"x":1795572000000,"y":0},{"x":1795572060000,"y":0},{"x":1795572120000,"y":0},{"x":1795572180000,"y":0},{"x":1795572240000,"y":0},{"x":1795572300000,"y":0},{"x":1795572360000,"y":0},{"x":1795572420000,"y":0},{"x":1795572480000,"y":0},{"x":1795572540000,"y":0},{"x":1795572600000,"y":0},{"x":1795572660000,"y":0},{"x":1795572720000,"y":0},{"x":1795572780000,"y":0},{"x":1795572840000,"y":0},{"x":1795572900000,"y":0},{"x":1795572960000,"y":0},{"x":1795573020000,"y":0},{"x":1795573080000,"y":0},{"x":1795573140000,"y":0},{"x":1795573200000,"y":0},{"x":1795573260000,"y":0},{"x":1795573320000,"y":0},{"x":1795573380000,"y":0},{"x":1795573440000,"y":0},{"x":1795573500000,"y":0},{"x":1795573560000,"y":0},{"x":1795573620000,"y":0},{"x":1795573680000,"y":0},{"x":1795573740000,"y":0},{"x":1795573800000,"y":0},{"x":1795573860000,"y":0},{"x":1795573920000,"y":0},{"x":1795573980000,"y":0},{"x":1795574040000,"y":0},{"x":1795574100000,"y":0},{"x":1795574160000,"y":0},{"x":1795574220000,"y":0},{"x":1795574280000,"y":0},{"x":1795574340000,"y":0},{"x":1795574700000,"y":0},{"x":1795574760000,"y":0},{"x":1795574820000,"y":0},{"x":1795574880000,"y":0},{"x":1795574940000,"y":0},{"x":1795575000000,"y":0},{"x":1795575060000,"y":0},{"x":1795575120000,"y":0},{"x":1795575180000,"y":0},{"x":1795575240000,"y":0}],"highlightExtremes":false,"unit":" mm"}], {"yLabel":"mm","yMin":0}); }); $('.modal').on('hide.bs.modal', function() { var memory = $(this).html(); $(this).html(memory); }); function meteo_wind_direction_name(wind_direction) { if (wind_direction >= 0.00 && wind_direction <= 11.25) { ret = 'S'; } else if (wind_direction > 11.25 && wind_direction <= 33.75) { ret = 'SSV'; } else if (wind_direction > 33.75 && wind_direction <= 56.25) { ret = 'SV'; } else if (wind_direction > 56.25 && wind_direction <= 78.75) { // 67.5 ret = 'VSV'; } else if (wind_direction > 78.75 && wind_direction <= 101.25) { // 90 ret = 'V'; } else if (wind_direction > 101.25 && wind_direction <= 123.75) { //112.5 ret = 'VJV'; } else if (wind_direction > 123.75 && wind_direction <= 146.25) { // 135 ret = 'JV'; } else if (wind_direction > 146.25 && wind_direction <= 168.75) { // 157.5 ret = 'JJV'; } else if (wind_direction > 168.75 && wind_direction <= 191.25) { // 180 ret = 'J'; } else if (wind_direction > 191.25 && wind_direction <= 213.75) { // 202.5 ret = 'JJZ'; } else if (wind_direction > 213.75 && wind_direction <= 236.25) { // 225 ret = 'JZ'; } else if (wind_direction > 236.25 && wind_direction <= 258.75) { // 247.5 ret = 'ZJZ'; } else if (wind_direction > 258.75 && wind_direction <= 281.25) { // 270 ret = 'Z'; } else if (wind_direction > 281.25 && wind_direction <= 303.75) { // 292.5 ret = 'ZSZ'; } else if (wind_direction > 303.75 && wind_direction <= 326.25) { // 315 ret = 'SZ'; } else if (wind_direction > 326.25 && wind_direction <= 348.75) { // 337.5 ret = 'SSZ'; } else if (wind_direction > 348.75 && wind_direction <= 360.0) { // 337.5 ret = 'S'; } else { return ''; } return ret; }