Skip to content

Commit

Permalink
Reverted using end timestamp for charts. GH-181
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveiano committed Jul 7, 2023
1 parent ccfd819 commit 11eed6b
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bin/user/weewx_wdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,8 +1601,8 @@ def get_diagram_props(self, obs, context):
elif obs in diagrams_config["combined_observations"]:
return {
**diagram_base_props,
**diagram_context_props,
**diagrams_config["combined_observations"][obs],
**diagram_context_props,
}
else:
return {
Expand Down
7 changes: 7 additions & 0 deletions skins/weewx-wdc/skin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ SKIN_VERSION = 3.2.0
[[[[[radiation]]]]]
[[[[[cloudbase]]]]]
[[[[[appTemp]]]]]
[[[[[climatogram_year]]]]]
bottom_date_time_format = "%b"
tooltip_date_time_format = "%B"


[[[alltime]]]
bottom_date_time_format = "%m/%y"
Expand All @@ -534,6 +538,9 @@ SKIN_VERSION = 3.2.0
[[[[[radiation]]]]]
[[[[[cloudbase]]]]]
[[[[[appTemp]]]]]
[[[[[climatogram_statistics]]]]]
bottom_date_time_format = "%Y"
tooltip_date_time_format = "%Y"

# Diagram heights.
[[[heights]]]
Expand Down
6 changes: 4 additions & 2 deletions skins/weewx-wdc/src/js/diagrams/d3/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export const D3BarDiagram: FunctionComponent<BarDiagramBaseProps> = (
x: number;
y: number;
start: number;
end: number;
}>({
x: 0,
y: 0,
start: 0,
end: 0,
});

// @todo This adds one MutationObserver per LineDiagram. Add this to one
Expand Down Expand Up @@ -315,7 +317,7 @@ export const D3BarDiagram: FunctionComponent<BarDiagramBaseProps> = (

const d = props.data[0].data[i];

setTooltip({ x: d.x, y: d.y, start: d.start });
setTooltip({ x: d.x, y: d.y, start: d.start, end: d.end });

d3.select(tooltipRef.current)
.style("display", "block")
Expand Down Expand Up @@ -377,7 +379,7 @@ export const D3BarDiagram: FunctionComponent<BarDiagramBaseProps> = (
) : (
<>
{dateTimeFormatTooltip(new Date(tooltip.start * 1000))} -{" "}
{dateTimeFormatTooltip(new Date(tooltip.x * 1000))}
{dateTimeFormatTooltip(new Date(tooltip.end * 1000))}
</>
)}
</div>
Expand Down
25 changes: 20 additions & 5 deletions skins/weewx-wdc/src/js/diagrams/d3/combined.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,36 @@ export const CombinedDiagram: FunctionComponent<CombinedDiagramBaseProps> = (
});

// Draw Axes.
// X Axis - use bar scaleBand for axis bottom.
// X Axis
// TODO: There should be some condition on which to either
// use bar scaleBand for axis bottom or the line scale? See GH-181
const barCharUnit = props.unit[props.chartTypes.indexOf("bar")];
const lineCharUnit = props.unit[props.chartTypes.indexOf("line")];

const numberOfBars =
dataGroupedByScale[`${barCharUnit}|bar`][0].data.length,
scaleToUseForXAxis = "bar"; //numberOfBars > 5 ? "line" : "bar";

svgElement
.append("g")
.attr("transform", `translate(0, ${height})`)
.attr("data-test", "x-axis")
.call(
d3
.axisBottom(scales[`${barCharUnit}|bar`]["x"])
.axisBottom(
scaleToUseForXAxis === "bar"
? scales[`${barCharUnit}|bar`]["x"]
: scales[`${lineCharUnit}|line`]["x"]
)
.tickSize(0)
.tickPadding(6)
.tickFormat((d) =>
dateTimeFormat(new Date(parseInt(d as string) * 1000))
)
.tickFormat((d) => {
if (typeof d === "object") {
return dateTimeFormat(d as Date);
} else {
return dateTimeFormat(new Date(parseInt(d as string) * 1000));
}
})
)
.selectAll("text")
.style("text-anchor", "end")
Expand Down
26 changes: 16 additions & 10 deletions skins/weewx-wdc/src/js/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,14 @@ diagrams.forEach((diagram) => {
observation: diagramObservations[index],
id: `${labels[index]} ${aggregate_types[index]}`,
data: (window as any)[serie]
.map((item: number[]) => ({
x: item[1],
y: item[2],
start: item[0],
}))
.map((item: number[]) => {
return {
x: item[0],
y: item[2],
start: item[0],
end: item[1],
};
})
.sort((a: Series, b: Series) => a.x - b.x),
},
];
Expand All @@ -146,11 +149,14 @@ diagrams.forEach((diagram) => {
observation: diagramObservations[0],
id: diagramObservations[0],
data: (window as any)[diagram.dataset.value]
.map((item: number[]) => ({
x: item[1],
y: item[2],
start: item[0],
}))
.map((item: number[]) => {
return {
x: item[0],
y: item[2],
start: item[0],
end: item[1],
};
})
.sort((a: Series, b: Series) => a.x - b.x),
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{'lineWidth': '2', 'pointSize': '3', 'isInteractive': 'True', 'enablePoints': 'True', 'enableCrosshair': 'True', 'yScaleOffset': '0.5', 'enableArea': 'False', 'areaOpacity': '0.07', 'curve': 'natural', 'bottom_date_time_format': '%m/%y', 'tooltip_date_time_format': '%m/%Y', 'label': 'Temperature Min/Max/Avg', 'markerValue': '0', 'markerColor': '#00BFFF', 'obs': {'outTemp_min': {'observation': 'outTemp', 'aggregate_type': 'min', 'color': '#0198E1'}, 'outTemp_average': {'observation': 'outTemp', 'aggregate_type': 'avg', 'color': '#666666'}, 'outTemp_max': {'observation': 'outTemp', 'aggregate_type': 'max', 'color': '#8B0000'}}}
{'lineWidth': '2', 'pointSize': '3', 'isInteractive': 'True', 'enablePoints': 'True', 'enableCrosshair': 'True', 'yScaleOffset': '0.5', 'enableArea': 'False', 'areaOpacity': '0.07', 'curve': 'natural', 'label': 'Temperature Min/Max/Avg', 'markerValue': '0', 'markerColor': '#00BFFF', 'obs': {'outTemp_min': {'observation': 'outTemp', 'aggregate_type': 'min', 'color': '#0198E1'}, 'outTemp_average': {'observation': 'outTemp', 'aggregate_type': 'avg', 'color': '#666666'}, 'outTemp_max': {'observation': 'outTemp', 'aggregate_type': 'max', 'color': '#8B0000'}}, 'bottom_date_time_format': '%m/%y', 'tooltip_date_time_format': '%m/%Y'}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{'lineWidth': '2', 'pointSize': '3', 'isInteractive': 'True', 'enablePoints': 'True', 'enableCrosshair': 'True', 'yScaleOffset': '0.5', 'enableArea': 'False', 'areaOpacity': '0.07', 'curve': 'natural', 'bottom_date_time_format': '%m/%y', 'tooltip_date_time_format': '%m/%Y', 'label': 'Temperature Min/Max/Avg', 'markerValue': '0', 'markerColor': '#00BFFF', 'obs': {'outTemp_min': {'observation': 'outTemp', 'aggregate_type': 'min', 'color': '#0198E1'}, 'outTemp_average': {'observation': 'outTemp', 'aggregate_type': 'avg', 'color': '#666666'}, 'outTemp_max': {'observation': 'outTemp', 'aggregate_type': 'max', 'color': '#8B0000'}}}
{'lineWidth': '2', 'pointSize': '3', 'isInteractive': 'True', 'enablePoints': 'True', 'enableCrosshair': 'True', 'yScaleOffset': '0.5', 'enableArea': 'False', 'areaOpacity': '0.07', 'curve': 'natural', 'label': 'Temperature Min/Max/Avg', 'markerValue': '0', 'markerColor': '#00BFFF', 'obs': {'outTemp_min': {'observation': 'outTemp', 'aggregate_type': 'min', 'color': '#0198E1'}, 'outTemp_average': {'observation': 'outTemp', 'aggregate_type': 'avg', 'color': '#666666'}, 'outTemp_max': {'observation': 'outTemp', 'aggregate_type': 'max', 'color': '#8B0000'}}, 'bottom_date_time_format': '%m/%y', 'tooltip_date_time_format': '%m/%Y'}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<path fill="none" data-test="line-outTemp" stroke="#0198E1" stroke-width="2" d="M0,140.294C1.457,132.962,2.913,125.631,4.369,127.941C5.825,130.252,7.281,142.205,8.738,149.118C10.196,156.03,11.655,157.903,13.107,153.971C14.559,150.038,16.004,140.301,17.476,137.647C18.948,134.993,20.446,139.423,21.918,139.853C23.39,140.283,24.835,136.713,26.287,137.647C27.739,138.581,29.199,144.018,30.656,145.588C32.114,147.158,33.569,144.86,35.025,144.706C36.481,144.551,37.938,146.54,39.394,151.765C40.851,156.989,42.307,165.449,43.763,165.441C45.22,165.434,46.676,156.958,48.132,156.176C49.589,155.395,51.045,162.306,52.501,160.588C53.958,158.871,55.414,148.524,56.87,146.471C58.327,144.417,59.783,150.655,61.239,157.941C62.696,165.227,64.152,173.561,65.608,174.265C67.065,174.969,68.521,168.043,69.977,168.529C71.434,169.016,72.89,176.915,74.347,176.029C75.803,175.144,77.259,165.474,78.716,165.441C80.172,165.408,81.628,175.013,83.085,177.794C84.541,180.575,85.997,176.532,87.454,174.706C88.91,172.879,90.366,173.269,91.823,176.471C93.279,179.672,94.735,185.685,96.192,181.765C97.648,177.844,99.104,163.99,100.561,157.5C102.017,151.01,103.473,151.885,104.93,155.735C106.386,159.585,107.843,166.411,109.299,172.5C110.755,178.589,112.212,183.943,113.668,185.294C115.124,186.645,116.581,183.994,118.037,189.706C119.493,195.418,120.95,209.494,122.406,207.794C123.862,206.095,125.319,188.62,126.775,170.735C128.231,152.851,129.688,134.556,131.144,128.382C132.6,122.208,134.057,128.154,135.513,139.412C136.969,150.669,138.426,167.238,139.882,173.824C141.339,180.409,142.795,177.011,144.251,176.912C145.708,176.813,147.164,180.012,148.62,182.206C150.077,184.4,151.533,185.587,152.989,184.853C154.446,184.118,155.902,181.462,157.358,177.794C158.815,174.127,160.271,169.449,161.727,172.5C163.184,175.551,164.64,186.331,166.096,186.176C167.553,186.022,169.009,174.932,170.465,170.735C171.922,166.539,173.378,169.235,174.835,170.294C176.291,171.353,177.747,170.775,179.204,169.412C180.66,168.048,182.116,165.899,183.573,166.765C185.029,167.63,186.485,171.511,187.942,169.412C189.398,167.313,190.854,159.235,192.311,158.382C193.767,157.53,195.223,163.902,196.68,163.235C198.136,162.568,199.592,154.862,201.049,157.941C202.505,161.02,203.961,174.884,205.418,177.794C206.874,180.704,208.331,172.66,209.787,165.441C211.243,158.223,212.7,151.83,214.156,152.206C215.612,152.582,217.069,159.726,218.525,161.029C219.981,162.332,221.438,157.794,222.894,157.059C224.35,156.324,225.807,159.391,227.263,163.235C228.719,167.079,230.176,171.699,231.632,175.147C233.088,178.595,234.545,180.87,236.001,182.206C237.457,183.542,238.914,183.938,240.37,182.647C241.826,181.356,243.283,178.379,244.739,178.676C246.196,178.974,247.652,182.546,249.108,184.412C250.565,186.278,252.021,186.437,253.477,182.206C254.934,177.975,256.39,169.353,257.846,161.912C259.303,154.471,260.759,148.211,262.215,152.206C263.672,156.201,265.129,170.451,266.584,174.265C268.04,178.079,269.493,171.457,270.953,167.647C272.414,163.837,273.882,162.84,275.322,160.147C276.763,157.454,278.178,153.065,279.619,153.971C281.06,154.876,282.527,161.075,283.988,164.118C285.448,167.16,286.902,167.046,288.357,172.941C289.812,178.836,291.269,190.739,292.726,187.941C294.182,185.143,295.639,167.643,297.095,159.265C298.551,150.886,300.008,151.63,301.464,156.618C302.92,161.606,304.377,170.839,305.833,169.412C307.289,167.985,308.746,155.898,310.202,153.529C311.658,151.161,313.115,158.512,314.571,163.676C316.027,168.841,317.484,171.821,318.94,172.5C320.396,173.179,321.853,171.558,323.309,167.206C324.765,162.853,326.222,155.769,327.678,153.971C329.135,152.172,330.591,155.66,332.047,156.176C333.504,156.693,334.96,154.238,336.416,152.206C337.873,150.174,339.329,148.564,340.785,146.912C342.242,145.26,343.698,143.566,345.154,142.059C346.611,140.551,348.067,139.23,349.523,140.294C350.98,141.358,352.436,144.808,353.892,139.853C355.349,134.898,356.805,121.537,358.261,120.882C359.718,120.227,361.174,132.278,362.631,137.206C364.087,142.134,365.543,139.939,367,136.324C368.456,132.708,369.912,127.673,371.369,121.765C372.825,115.856,374.281,109.074,375.738,112.059C377.194,115.044,378.65,127.795,380.107,129.706C381.563,131.617,383.019,122.687,384.476,123.971C385.932,125.255,387.388,136.753,388.845,142.941C390.301,149.13,391.757,150.009,393.214,146.912C394.67,143.815,396.127,136.741,397.583,130.588C399.039,124.435,400.496,119.204,401.952,115.147C403.408,111.091,404.865,108.21,406.321,110.294C407.777,112.379,409.234,119.429,410.69,119.559C412.146,119.689,413.603,112.899,415.059,114.706C416.515,116.512,417.972,126.915,419.428,129.706C420.884,132.496,422.339,127.674,423.797,123.971C425.255,120.267,426.715,117.681,428.166,118.235C429.617,118.789,431.059,122.483,432.5,126.176"></path>
<path fill="none" data-test="line-outTemp" stroke="#0198E1" stroke-width="2" d="M0,140.294C1.456,132.962,2.912,125.631,4.369,127.941C5.825,130.252,7.281,142.205,8.737,149.118C10.193,156.03,11.649,157.903,13.106,153.971C14.563,150.038,16.023,140.301,17.475,137.647C18.927,134.993,20.372,139.423,21.843,139.853C23.315,140.283,24.813,136.713,26.285,137.647C27.757,138.581,29.202,144.018,30.654,145.588C32.106,147.158,33.565,144.86,35.022,144.706C36.48,144.551,37.935,146.54,39.391,151.765C40.847,156.989,42.303,165.449,43.76,165.441C45.216,165.434,46.672,156.958,48.128,156.176C49.585,155.395,51.041,162.306,52.497,160.588C53.953,158.871,55.41,148.524,56.866,146.471C58.322,144.417,59.778,150.655,61.234,157.941C62.691,165.227,64.147,173.561,65.603,174.265C67.059,174.969,68.516,168.043,69.972,168.529C71.428,169.016,72.884,176.915,74.34,176.029C75.797,175.144,77.253,165.474,78.709,165.441C80.165,165.408,81.622,175.013,83.078,177.794C84.534,180.575,85.99,176.532,87.447,174.706C88.903,172.879,90.359,173.269,91.815,176.471C93.271,179.672,94.728,185.685,96.184,181.765C97.64,177.844,99.096,163.99,100.553,157.5C102.009,151.01,103.465,151.885,104.921,155.735C106.378,159.585,107.834,166.411,109.29,172.5C110.746,178.589,112.202,183.943,113.659,185.294C115.115,186.645,116.571,183.994,118.027,189.706C119.484,195.418,120.94,209.494,122.396,207.794C123.852,206.095,125.309,188.62,126.765,170.735C128.221,152.851,129.677,134.556,131.133,128.382C132.59,122.208,134.046,128.154,135.502,139.412C136.958,150.669,138.415,167.238,139.871,173.824C141.327,180.409,142.783,177.011,144.239,176.912C145.696,176.813,147.152,180.012,148.608,182.206C150.064,184.4,151.521,185.587,152.977,184.853C154.433,184.118,155.889,181.462,157.346,177.794C158.802,174.127,160.258,169.449,161.714,172.5C163.17,175.551,164.627,186.331,166.083,186.176C167.539,186.022,168.995,174.932,170.452,170.735C171.908,166.539,173.364,169.235,174.82,170.294C176.277,171.353,177.733,170.775,179.189,169.412C180.645,168.048,182.101,165.899,183.558,166.765C185.014,167.63,186.47,171.511,187.926,169.412C189.383,167.313,190.839,159.235,192.295,158.382C193.751,157.53,195.207,163.902,196.664,163.235C198.12,162.568,199.576,154.862,201.032,157.941C202.489,161.02,203.945,174.884,205.401,177.794C206.857,180.704,208.314,172.66,209.77,165.441C211.226,158.223,212.682,151.83,214.138,152.206C215.595,152.582,217.051,159.726,218.507,161.029C219.963,162.332,221.42,157.794,222.876,157.059C224.332,156.324,225.788,159.391,227.245,163.235C228.701,167.079,230.157,171.699,231.613,175.147C233.069,178.595,234.526,180.87,235.982,182.206C237.438,183.542,238.894,183.938,240.351,182.647C241.807,181.356,243.263,178.379,244.719,178.676C246.176,178.974,247.632,182.546,249.088,184.412C250.544,186.278,252,186.437,253.457,182.206C254.913,177.975,256.369,169.353,257.825,161.912C259.282,154.471,260.738,148.211,262.194,152.206C263.65,156.201,265.106,170.451,266.563,174.265C268.019,178.079,269.476,171.457,270.931,167.647C272.387,163.837,273.84,162.84,275.3,160.147C276.76,157.454,278.228,153.065,279.669,153.971C281.11,154.876,282.524,161.075,283.965,164.118C285.405,167.16,286.873,167.046,288.333,172.941C289.794,178.836,291.247,190.739,292.702,187.941C294.157,185.143,295.614,167.643,297.071,159.265C298.527,150.886,299.983,151.63,301.439,156.618C302.896,161.606,304.352,170.839,305.808,169.412C307.264,167.985,308.721,155.898,310.177,153.529C311.633,151.161,313.089,158.512,314.545,163.676C316.002,168.841,317.458,171.821,318.914,172.5C320.37,173.179,321.827,171.558,323.283,167.206C324.739,162.853,326.195,155.769,327.652,153.971C329.108,152.172,330.564,155.66,332.02,156.176C333.476,156.693,334.933,154.238,336.389,152.206C337.845,150.174,339.301,148.564,340.758,146.912C342.214,145.26,343.67,143.566,345.126,142.059C346.582,140.551,348.039,139.23,349.495,140.294C350.951,141.358,352.407,144.808,353.864,139.853C355.32,134.898,356.776,121.537,358.232,120.882C359.689,120.227,361.145,132.278,362.601,137.206C364.057,142.134,365.513,139.939,366.97,136.324C368.426,132.708,369.882,127.673,371.338,121.765C372.795,115.856,374.251,109.074,375.707,112.059C377.163,115.044,378.62,127.795,380.076,129.706C381.532,131.617,382.988,122.687,384.444,123.971C385.901,125.255,387.357,136.753,388.813,142.941C390.269,149.13,391.726,150.009,393.182,146.912C394.638,143.815,396.094,136.741,397.551,130.588C399.007,124.435,400.463,119.204,401.919,115.147C403.375,111.091,404.832,108.21,406.288,110.294C407.744,112.379,409.2,119.429,410.657,119.559C412.113,119.689,413.569,112.899,415.025,114.706C416.481,116.512,417.938,126.915,419.394,129.706C420.85,132.496,422.306,127.674,423.763,123.971C425.219,120.267,426.675,117.681,428.131,118.235C429.588,118.789,431.044,122.483,432.5,126.176"></path>
Loading

0 comments on commit 11eed6b

Please sign in to comment.