|
@@ -1,36 +1,155 @@
|
|
|
-<!--
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2024-09-11 14:31:05
|
|
|
- * @LastEditTime: 2024-09-29 17:03:38
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/chartsCom/WindRoseChart.vue
|
|
|
--->
|
|
|
<template>
|
|
|
<div>
|
|
|
- WindRoseChart
|
|
|
<h1>风向玫瑰分析</h1>
|
|
|
- <div :id="`chart-${inds}`" style="width: 100%; height: 550px"></div>
|
|
|
+ <div :id="`plotDiv-${inds}`" style="width: 100%; height: 550px"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
+
|
|
|
<script>
|
|
|
-import { allTypesDatas } from "@/utils/allTypesOfAnalysisData.js";
|
|
|
import Plotly from "plotly.js-dist";
|
|
|
+
|
|
|
export default {
|
|
|
- props: {},
|
|
|
- data() {
|
|
|
- return {};
|
|
|
+ props: {
|
|
|
+ data: {
|
|
|
+ type: Array,
|
|
|
+ default: () => [
|
|
|
+ { windSpeed: 2.5, windDirection: 30 },
|
|
|
+ { windSpeed: 4.8, windDirection: 60 },
|
|
|
+ { windSpeed: 7.2, windDirection: 90 },
|
|
|
+ { windSpeed: 9.1, windDirection: 120 },
|
|
|
+ { windSpeed: 3.5, windDirection: 150 },
|
|
|
+ { windSpeed: 5.6, windDirection: 180 },
|
|
|
+ { windSpeed: 8.3, windDirection: 210 },
|
|
|
+ { windSpeed: 6.4, windDirection: 240 },
|
|
|
+ { windSpeed: 2.9, windDirection: 270 },
|
|
|
+ { windSpeed: 7.7, windDirection: 300 },
|
|
|
+ { windSpeed: 3.2, windDirection: 330 },
|
|
|
+ { windSpeed: 4.0, windDirection: 360 },
|
|
|
+ { windSpeed: 5.1, windDirection: 45 },
|
|
|
+ { windSpeed: 6.9, windDirection: 75 },
|
|
|
+ { windSpeed: 8.6, windDirection: 105 },
|
|
|
+ { windSpeed: 7.0, windDirection: 135 },
|
|
|
+ { windSpeed: 4.5, windDirection: 165 },
|
|
|
+ { windSpeed: 9.0, windDirection: 195 },
|
|
|
+ { windSpeed: 3.8, windDirection: 225 },
|
|
|
+ { windSpeed: 5.9, windDirection: 255 },
|
|
|
+ { windSpeed: 7.5, windDirection: 285 },
|
|
|
+ { windSpeed: 6.0, windDirection: 315 },
|
|
|
+ { windSpeed: 2.7, windDirection: 345 },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ inds: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: 1,
|
|
|
+ },
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.initcharts();
|
|
|
+ this.renderChart();
|
|
|
},
|
|
|
methods: {
|
|
|
- initcharts() {
|
|
|
- const lineDatas = allTypesDatas.filter(
|
|
|
- (item) => item.analysisTypeCode === "wind_direction_frequency"
|
|
|
- )[0];
|
|
|
+ renderChart() {
|
|
|
+ const bins = [0, 3, 6, 9, Infinity];
|
|
|
+ const speedLabels = ["[0,3)", "[3,6)", "[6,9)", ">=9"];
|
|
|
+ const windDirections = Array.from({ length: 16 }, (_, i) => i * 22.5);
|
|
|
+ const directionLabels = [
|
|
|
+ "N",
|
|
|
+ "NNE",
|
|
|
+ "NE",
|
|
|
+ "ENE",
|
|
|
+ "E",
|
|
|
+ "ESE",
|
|
|
+ "SE",
|
|
|
+ "SSE",
|
|
|
+ "S",
|
|
|
+ "SSW",
|
|
|
+ "SW",
|
|
|
+ "WSW",
|
|
|
+ "W",
|
|
|
+ "WNW",
|
|
|
+ "NW",
|
|
|
+ "NNW",
|
|
|
+ ];
|
|
|
+ const colorscale = {
|
|
|
+ "[0,3)": "rgba(247, 251, 255, 1.0)",
|
|
|
+ "[3,6)": "rgba(171, 207, 229, 1.0)",
|
|
|
+ "[6,9)": "rgba(55, 135, 192, 1.0)",
|
|
|
+ ">=9": "rgba(8, 48, 107, 1.0)",
|
|
|
+ };
|
|
|
+
|
|
|
+ const speedBins = this.data.map((item) => {
|
|
|
+ for (let i = 0; i < bins.length - 1; i++) {
|
|
|
+ if (item.windSpeed >= bins[i] && item.windSpeed < bins[i + 1]) {
|
|
|
+ return speedLabels[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ">=9";
|
|
|
+ });
|
|
|
+
|
|
|
+ const directionBins = this.data.map((item) => {
|
|
|
+ return windDirections.find(
|
|
|
+ (d, i) =>
|
|
|
+ item.windDirection >= d &&
|
|
|
+ item.windDirection < windDirections[i + 1]
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ const counts = {};
|
|
|
+ speedLabels.forEach((speedLabel) => {
|
|
|
+ counts[speedLabel] = Array(windDirections.length - 1).fill(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.data.forEach((item, i) => {
|
|
|
+ const speedLabel = speedBins[i];
|
|
|
+ const directionBin = directionBins[i];
|
|
|
+ const index = windDirections.indexOf(directionBin);
|
|
|
+ counts[speedLabel][index]++;
|
|
|
+ });
|
|
|
+
|
|
|
+ const traces = speedLabels.map((speedLabel) => {
|
|
|
+ const percentage = counts[speedLabel].map(
|
|
|
+ (c) => (c / this.data.length) * 100
|
|
|
+ );
|
|
|
+ return {
|
|
|
+ r: percentage,
|
|
|
+ theta: windDirections,
|
|
|
+ name: speedLabel,
|
|
|
+ type: "barpolar",
|
|
|
+ marker: {
|
|
|
+ color: colorscale[speedLabel],
|
|
|
+ line: {
|
|
|
+ color: "white",
|
|
|
+ width: 1,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ const layout = {
|
|
|
+ title: "Wind Rose",
|
|
|
+ plot_bgcolor: "#e5ecf6",
|
|
|
+ polar: {
|
|
|
+ bgcolor: "#e5ecf6",
|
|
|
+ radialaxis: {
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ showgrid: true,
|
|
|
+ linecolor: "rgb(255,255,255)",
|
|
|
+ },
|
|
|
+ angularaxis: {
|
|
|
+ tickvals: windDirections,
|
|
|
+ ticktext: directionLabels,
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ tickcolor: "rgb(255,255,255)",
|
|
|
+ linecolor: "rgb(255,255,255)",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ showlegend: true,
|
|
|
+ legend: { title: { text: "Wind Speed" } },
|
|
|
+ };
|
|
|
+
|
|
|
+ Plotly.newPlot(`plotDiv-${this.inds}`, traces, layout);
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
+
|
|
|
<style scoped></style>
|