File size: 5,274 Bytes
9756872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your Thought Plot</title>
    <style>
      body {
        font-family: "Helvetica Neue", sans-serif;
        background-color: #ffffff;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100vh;
        color: #333;
      }
      .heading {
        text-align: center;
        font-size: 52px;
        font-weight: bold;
        margin-top: -200px;
      }
      .subheading {
        text-align: center;
        font-size: 34px;
        margin-bottom: 40px;
      }
      .container {
        width: 90%;
        max-width: 800px;
        height: 500px;
        position: relative;
      }
      #graphCanvas {
        width: 100%;
        height: 100%;
      }
      .axis-label {
        color: #000;
        font-weight: bold;
        transition: font-size 0.2s ease-in-out;
      }
      .y-axis-label {
        position: absolute;
        top: 50%;
        left: -90px;
        transform: translateY(-50%) rotate(-90deg);
      }
      .x-axis-label {
        position: absolute;
        bottom: -60px;
        left: 50%;
        transform: translateX(-50%);
      }
    </style>
  </head>
  <body>
    <div class="heading">Your Thought Plot</div>
    <div class="subheading">Forward Flow: Custom Plot</div>
    <div class="container">
      <canvas id="graphCanvas" width="800" height="500"></canvas>
      <div class="y-axis-label axis-label">Forward Flow</div>
      <div class="x-axis-label axis-label">Words</div>
    </div>

    <script>
      const canvas = document.getElementById("graphCanvas");
      const ctx = canvas.getContext("2d");

      // Get values from the URL
      const urlParams = new URLSearchParams(window.location.search);
      const xValues = urlParams
        .get("xValues")
        .split(",")
        .map((val) => val.trim());
      const yValues = urlParams
        .get("yValues")
        .split(",")
        .map((val) => parseFloat(val.trim()));

      const maxValues = 12;
      const displayValues =
        xValues.length > maxValues ? xValues.slice(0, maxValues) : xValues;
      const displayYValues =
        yValues.length > maxValues ? yValues.slice(0, maxValues) : yValues;

      const padding = 70;
      const extraPadding = 20;
      const xExtend = canvas.width * 0.05;
      const graphWidth = canvas.width - padding * 2 + xExtend + extraPadding;
      const graphHeight = canvas.height - padding * 2;

      // Adjust font size based on the number of x-values
      const maxFontSize = 32;
      const minFontSize = 14;
      const fontSize = Math.max(
        minFontSize,
        maxFontSize - displayValues.length * 1.5
      );
      ctx.font = `${fontSize}px Helvetica Neue`;

      // Update the axis labels' font size
      document.querySelectorAll(".axis-label").forEach((label) => {
        label.style.fontSize = `${fontSize}px`;
      });

      ctx.clearRect(0, 0, canvas.width, canvas.height);

      // Draw Y axis line
      ctx.beginPath();
      ctx.moveTo(padding, padding);
      ctx.lineTo(padding, canvas.height - padding + extraPadding);
      ctx.strokeStyle = "#000";
      ctx.lineWidth = 3;
      ctx.stroke();

      ctx.fillStyle = "#000";
      ctx.textAlign = "right";
      ctx.fillText(
        "0",
        padding - 10,
        canvas.height - padding + 10 + extraPadding
      );
      ctx.fillText("1", padding, padding + 10);

      // Draw y-axis values
      const ySteps = 5;
      for (let i = 1; i < ySteps; i++) {
        const yValue = (i / ySteps).toFixed(2);
        const yPos =
          canvas.height - padding - yValue * graphHeight + extraPadding;
        ctx.fillText(yValue, padding - 10, yPos + 5);
      }

      // Draw X axis line
      ctx.beginPath();
      ctx.moveTo(padding, canvas.height - padding + extraPadding);
      ctx.lineTo(
        canvas.width - padding + xExtend,
        canvas.height - padding + extraPadding
      );
      ctx.strokeStyle = "#000";
      ctx.lineWidth = 3;
      ctx.stroke();

      // Plot points and draw line
      const xStep = graphWidth / (displayValues.length - 1);
      ctx.beginPath();
      ctx.strokeStyle = "#000";
      ctx.lineWidth = 3;
      ctx.moveTo(
        padding,
        canvas.height - padding - displayYValues[0] * graphHeight + extraPadding
      );
      displayYValues.forEach((value, index) => {
        const x = padding + index * xStep;
        const y = canvas.height - padding - value * graphHeight + extraPadding;
        ctx.lineTo(x, y);
      });
      ctx.stroke();

      // Draw points and labels
      ctx.fillStyle = "#000";
      displayYValues.forEach((value, index) => {
        const x = padding + index * xStep;
        const y = canvas.height - padding - value * graphHeight + extraPadding;
        ctx.beginPath();
        ctx.arc(x, y, 6, 0, 2 * Math.PI);
        ctx.fill();
        ctx.textAlign = "center";
        ctx.fillText(
          displayValues[index],
          x,
          canvas.height - padding + 30 + extraPadding
        );
      });
    </script>
  </body>
</html>