OzoneAsai commited on
Commit
f2f3129
·
verified ·
1 Parent(s): 310edae

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +102 -25
index.html CHANGED
@@ -7,14 +7,10 @@
7
  body {
8
  font-family: Arial, sans-serif;
9
  text-align: center;
 
 
10
  }
11
- .chart-container {
12
- display: inline-block;
13
- margin: 20px;
14
- }
15
- svg {
16
- border: 1px solid #ccc;
17
- }
18
  button {
19
  padding: 10px 20px;
20
  font-size: 16px;
@@ -35,10 +31,10 @@
35
  }
36
  .modal-content {
37
  background-color: #fefefe;
38
- margin: 10% auto; /* 上下にマージン、中央揃え */
39
  padding: 20px;
40
  border: 1px solid #888;
41
- width: 80%; /* 幅を80%に */
42
  max-width: 600px; /* 最大幅を600pxに */
43
  border-radius: 8px;
44
  position: relative;
@@ -78,6 +74,39 @@
78
  .modal-buttons button {
79
  margin-left: 10px;
80
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  </style>
82
  <!-- D3.jsの読み込み -->
83
  <script src="https://d3js.org/d3.v7.min.js"></script>
@@ -90,21 +119,21 @@
90
  <div id="charts">
91
  <div class="chart-container">
92
  <h3>左センサー</h3>
93
- <svg id="leftChart" width="500" height="200"></svg>
94
  </div>
95
  <div class="chart-container">
96
  <h3>中央センサー</h3>
97
- <svg id="centerChart" width="500" height="200"></svg>
98
  </div>
99
  <div class="chart-container">
100
  <h3>右センサー</h3>
101
- <svg id="rightChart" width="500" height="200"></svg>
102
  </div>
103
  </div>
104
 
105
  <div id="rawDataOutput">
106
  <h2>Rawデータ</h2>
107
- <pre id="rawDataDisplay" style="text-align: left; width: 80%; margin: 0 auto; max-height: 200px; overflow: auto; border: 1px solid #ccc; padding: 10px;"></pre>
108
  </div>
109
 
110
  <!-- モーダルダイアログ -->
@@ -287,25 +316,26 @@
287
  }
288
  };
289
 
290
- const width = 500;
291
- const height = 200;
292
- const margin = {top: 20, right: 30, bottom: 30, left: 50};
293
-
294
  function initCharts() {
295
  for (let key in charts) {
296
  const chart = charts[key];
 
 
 
 
 
297
  // スケールの設定
298
- chart.xScale = d3.scaleLinear().domain([0, MAX_POINTS - 1]).range([margin.left, width - margin.right]);
299
- chart.yScale = d3.scaleLinear().domain([0, 1023]).range([height - margin.bottom, margin.top]); // 初期Y軸スケール
300
 
301
  // 軸の追加
302
  chart.svg.append("g")
303
- .attr("transform", `translate(0,${height - margin.bottom})`)
304
  .attr("class", "x-axis")
305
  .call(d3.axisBottom(chart.xScale));
306
 
307
  chart.svg.append("g")
308
- .attr("transform", `translate(${margin.left},0)`)
309
  .attr("class", "y-axis")
310
  .call(d3.axisLeft(chart.yScale));
311
 
@@ -322,6 +352,11 @@
322
  .attr("stroke-width", 2)
323
  .attr("d", chart.line);
324
  }
 
 
 
 
 
325
  }
326
 
327
  initCharts();
@@ -467,6 +502,15 @@
467
  function updateCharts() {
468
  for (let key in charts) {
469
  const chart = charts[key];
 
 
 
 
 
 
 
 
 
470
  // Yスケールの更新
471
  let yMin, yMax;
472
  if (includeZeroCheckbox.checked) {
@@ -487,17 +531,50 @@
487
  // パスの更新
488
  chart.path
489
  .datum(chart.data)
 
 
490
  .attr("d", chart.line);
491
  }
 
492
 
493
- // Xスケールの更新(常に0からMAX_POINTS -1)
 
 
 
494
  for (let key in charts) {
495
  const chart = charts[key];
496
- chart.xScale.domain([0, MAX_POINTS - 1]);
497
- chart.svg.select(".x-axis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  .transition()
499
  .duration(500)
500
- .call(d3.axisBottom(chart.xScale));
 
 
 
 
 
 
 
501
  }
502
  }
503
 
 
7
  body {
8
  font-family: Arial, sans-serif;
9
  text-align: center;
10
+ margin: 0;
11
+ padding: 0;
12
  }
13
+ /* ボタンのスタイル */
 
 
 
 
 
 
14
  button {
15
  padding: 10px 20px;
16
  font-size: 16px;
 
31
  }
32
  .modal-content {
33
  background-color: #fefefe;
34
+ margin: 5% auto; /* 上下にマージン、中央揃え */
35
  padding: 20px;
36
  border: 1px solid #888;
37
+ width: 90%; /* 幅を90%に */
38
  max-width: 600px; /* 最大幅を600pxに */
39
  border-radius: 8px;
40
  position: relative;
 
74
  .modal-buttons button {
75
  margin-left: 10px;
76
  }
77
+ /* グラフコンテナのスタイル */
78
+ #charts {
79
+ display: block;
80
+ width: 100%;
81
+ box-sizing: border-box;
82
+ }
83
+ .chart-container {
84
+ width: 100%;
85
+ height: 30vh; /* ビューポート高さの30% */
86
+ margin: 10px 0;
87
+ position: relative;
88
+ }
89
+ svg {
90
+ width: 100%;
91
+ height: 100%;
92
+ border: 1px solid #ccc;
93
+ box-sizing: border-box;
94
+ }
95
+ /* Rawデータ表示のスタイル */
96
+ #rawDataOutput {
97
+ width: 90%;
98
+ margin: 20px auto;
99
+ text-align: left;
100
+ }
101
+ #rawDataDisplay {
102
+ width: 100%;
103
+ max-height: 200px;
104
+ overflow: auto;
105
+ border: 1px solid #ccc;
106
+ padding: 10px;
107
+ background-color: #f9f9f9;
108
+ white-space: pre-wrap;
109
+ }
110
  </style>
111
  <!-- D3.jsの読み込み -->
112
  <script src="https://d3js.org/d3.v7.min.js"></script>
 
119
  <div id="charts">
120
  <div class="chart-container">
121
  <h3>左センサー</h3>
122
+ <svg id="leftChart"></svg>
123
  </div>
124
  <div class="chart-container">
125
  <h3>中央センサー</h3>
126
+ <svg id="centerChart"></svg>
127
  </div>
128
  <div class="chart-container">
129
  <h3>右センサー</h3>
130
+ <svg id="rightChart"></svg>
131
  </div>
132
  </div>
133
 
134
  <div id="rawDataOutput">
135
  <h2>Rawデータ</h2>
136
+ <pre id="rawDataDisplay"></pre>
137
  </div>
138
 
139
  <!-- モーダルダイアログ -->
 
316
  }
317
  };
318
 
 
 
 
 
319
  function initCharts() {
320
  for (let key in charts) {
321
  const chart = charts[key];
322
+ const svgElement = chart.svg.node();
323
+ const boundingRect = svgElement.getBoundingClientRect();
324
+ const width = boundingRect.width;
325
+ const height = boundingRect.height;
326
+
327
  // スケールの設定
328
+ chart.xScale = d3.scaleLinear().domain([0, MAX_POINTS - 1]).range([50, width - 50]);
329
+ chart.yScale = d3.scaleLinear().domain([0, 1023]).range([height - 30, 20]); // マージンを考慮
330
 
331
  // 軸の追加
332
  chart.svg.append("g")
333
+ .attr("transform", `translate(0,${height - 30})`)
334
  .attr("class", "x-axis")
335
  .call(d3.axisBottom(chart.xScale));
336
 
337
  chart.svg.append("g")
338
+ .attr("transform", `translate(50,0)`)
339
  .attr("class", "y-axis")
340
  .call(d3.axisLeft(chart.yScale));
341
 
 
352
  .attr("stroke-width", 2)
353
  .attr("d", chart.line);
354
  }
355
+
356
+ // リサイズイベントの設定
357
+ window.addEventListener('resize', () => {
358
+ resizeCharts();
359
+ });
360
  }
361
 
362
  initCharts();
 
502
  function updateCharts() {
503
  for (let key in charts) {
504
  const chart = charts[key];
505
+ const svgElement = chart.svg.node();
506
+ const boundingRect = svgElement.getBoundingClientRect();
507
+ const width = boundingRect.width;
508
+ const height = boundingRect.height;
509
+
510
+ // スケールの再設定
511
+ chart.xScale.range([50, width - 50]);
512
+ chart.yScale.range([height - 30, 20]); // マージンを考慮
513
+
514
  // Yスケールの更新
515
  let yMin, yMax;
516
  if (includeZeroCheckbox.checked) {
 
531
  // パスの更新
532
  chart.path
533
  .datum(chart.data)
534
+ .transition()
535
+ .duration(500)
536
  .attr("d", chart.line);
537
  }
538
+ }
539
 
540
+ // -------------------------------
541
+ // グラフのリサイズ関数
542
+ // -------------------------------
543
+ function resizeCharts() {
544
  for (let key in charts) {
545
  const chart = charts[key];
546
+ const svgElement = chart.svg.node();
547
+ const boundingRect = svgElement.getBoundingClientRect();
548
+ const width = boundingRect.width;
549
+ const height = boundingRect.height;
550
+
551
+ // スケールの更新
552
+ chart.xScale.range([50, width - 50]);
553
+ chart.yScale.range([height - 30, 20]); // マージンを考慮
554
+
555
+ // Yスケールの更新
556
+ let yMin, yMax;
557
+ if (includeZeroCheckbox.checked) {
558
+ yMin = d3.min(chart.data.concat([0])) || 0;
559
+ yMax = d3.max(chart.data.concat([0])) || 1023;
560
+ } else {
561
+ yMin = d3.min(chart.data) || 0;
562
+ yMax = d3.max(chart.data) || 1023;
563
+ }
564
+ chart.yScale.domain([Math.min(yMin, 0), Math.max(yMax, 0)]);
565
+
566
+ // Y軸の再描画
567
+ chart.svg.select(".y-axis")
568
  .transition()
569
  .duration(500)
570
+ .call(d3.axisLeft(chart.yScale));
571
+
572
+ // パスの更新
573
+ chart.path
574
+ .datum(chart.data)
575
+ .transition()
576
+ .duration(500)
577
+ .attr("d", chart.line);
578
  }
579
  }
580