|
1 | 1 | import { Graph, positiveRange } from './Graph.js';
|
| 2 | +import { drawPolygon } from '../jsxgraphUtils.js'; |
2 | 3 |
|
3 | 4 | export const defaults = [
|
4 | 5 | {
|
@@ -81,17 +82,17 @@ const sq2 = function(a, b, c, d, f, g) {
|
81 | 82 | return (a - c - f) / (b + d + g);
|
82 | 83 | };
|
83 | 84 |
|
84 |
| -/*const psurplus2 = function(a, b, c, d) { |
| 85 | +const psurplus2 = function(a, b, c, d) { |
85 | 86 | return (ep2(a, b, c, d) - c) * eq2(a, b, c, d) / 2;
|
86 |
| -};*/ |
| 87 | +}; |
87 | 88 |
|
88 |
| -/*const emcmarket2 = function(a, b, c, d, f, g) { |
| 89 | +const emcmarket2 = function(a, b, c, d, f, g) { |
89 | 90 | return f + g * eq2(a, b, c, d);
|
90 |
| -};*/ |
| 91 | +}; |
91 | 92 |
|
92 |
| -/*const extcost2 = function(a, b, c, d, f, g) { |
| 93 | +const extcost2 = function(a, b, c, d, f, g) { |
93 | 94 | return emcmarket2(a, b, c, d, f, g) * eq2(a, b, c, d) / 2;
|
94 |
| -};*/ |
| 95 | +}; |
95 | 96 |
|
96 | 97 | const spoint2 = function(a, b, c, d, f, g) {
|
97 | 98 | return [sq2(a, b, c, d, f, g), sp2(a, b, c, d, f, g)];
|
@@ -120,28 +121,101 @@ const evint2 = function(a, b, c, d) {
|
120 | 121 |
|
121 | 122 | export class NegativeProductionExternalityIndustryGraph extends Graph {
|
122 | 123 | static getGraphPane(gFunctionChoice, gA1, gA2, gA3, gA4, gA5, gA6) {
|
123 |
| - return [ |
124 |
| - { |
125 |
| - label: 'Unregulated Output Q*', |
126 |
| - color: 'red', |
127 |
| - value: eq2(gA1, gA2, gA3, gA4).toFixed(2) |
128 |
| - }, |
129 |
| - { |
130 |
| - label: 'Unregulated Price P*', |
131 |
| - color: 'red', |
132 |
| - value: ep2(gA1, gA2, gA3, gA4).toFixed(2) |
133 |
| - }, |
134 |
| - { |
135 |
| - label: 'Socially Desirable Output Q<sup>soc</sup>', |
136 |
| - color: 'orange', |
137 |
| - value: sq2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
138 |
| - }, |
139 |
| - { |
140 |
| - label: 'Socially Desirable Price P<sup>soc</sup>', |
141 |
| - color: 'orange', |
142 |
| - value: sp2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
143 |
| - }, |
144 |
| - ]; |
| 124 | + if (gFunctionChoice === 0) { |
| 125 | + return [ |
| 126 | + { |
| 127 | + label: 'Unregulated Output Q*', |
| 128 | + color: 'red', |
| 129 | + value: eq2(gA1, gA2, gA3, gA4).toFixed(2) |
| 130 | + }, |
| 131 | + { |
| 132 | + label: 'Unregulated Price P*', |
| 133 | + color: 'red', |
| 134 | + value: ep2(gA1, gA2, gA3, gA4).toFixed(2) |
| 135 | + }, |
| 136 | + { |
| 137 | + label: 'Socially Desirable Output Q<sup>soc</sup>', |
| 138 | + color: 'orange', |
| 139 | + value: sq2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 140 | + }, |
| 141 | + { |
| 142 | + label: 'Socially Desirable Price P<sup>soc</sup>', |
| 143 | + color: 'orange', |
| 144 | + value: sp2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 145 | + }, |
| 146 | + ]; |
| 147 | + } else if (gFunctionChoice === 1) { |
| 148 | + return [ |
| 149 | + { |
| 150 | + label: 'Unregulated Output Q*', |
| 151 | + color: 'red', |
| 152 | + value: eq2(gA1, gA2, gA3, gA4).toFixed(2) |
| 153 | + }, |
| 154 | + { |
| 155 | + label: 'Producer Surplus PS', |
| 156 | + color: 'orange', |
| 157 | + value: psurplus2(gA1, gA2, gA3, gA4).toFixed(2) |
| 158 | + }, |
| 159 | + { |
| 160 | + label: 'External Total Cost', |
| 161 | + color: 'red', |
| 162 | + value: extcost2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 163 | + }, |
| 164 | + { |
| 165 | + label: 'P*', |
| 166 | + color: 'red', |
| 167 | + value: ep2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 168 | + }, |
| 169 | + ]; |
| 170 | + } else if (gFunctionChoice === 2) { |
| 171 | + return [ |
| 172 | + { |
| 173 | + label: 'Unregulated Output Q*', |
| 174 | + color: 'red', |
| 175 | + value: eq2(gA1, gA2, gA3, gA4).toFixed(2) |
| 176 | + }, |
| 177 | + { |
| 178 | + label: 'Socially Desirable Output Q<sup>soc</sup>', |
| 179 | + color: 'orange', |
| 180 | + value: sq2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 181 | + }, |
| 182 | + { |
| 183 | + label: 'Producer Surplus PS', |
| 184 | + color: 'orange', |
| 185 | + value: psurplus2(gA1, gA2, gA3, gA4).toFixed(2) |
| 186 | + }, |
| 187 | + { |
| 188 | + label: 'Producer Surplus Loss', |
| 189 | + color: 'orange', |
| 190 | + value: psurplus2(gA1, gA2, gA3, gA4).toFixed(2) |
| 191 | + }, |
| 192 | + { |
| 193 | + label: 'Market Loss', |
| 194 | + color: 'orange', |
| 195 | + value: psurplus2(gA1, gA2, gA3, gA4).toFixed(2) |
| 196 | + }, |
| 197 | + { |
| 198 | + label: 'External Total Cost', |
| 199 | + color: 'red', |
| 200 | + value: extcost2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 201 | + }, |
| 202 | + { |
| 203 | + label: 'External Cost Reduction', |
| 204 | + color: 'red', |
| 205 | + value: extcost2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 206 | + }, |
| 207 | + { |
| 208 | + label: 'P*', |
| 209 | + color: 'red', |
| 210 | + value: ep2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 211 | + }, |
| 212 | + { |
| 213 | + label: 'P<sup>soc</sup>', |
| 214 | + color: 'red', |
| 215 | + value: ep2(gA1, gA2, gA3, gA4, gA5, gA6).toFixed(2) |
| 216 | + }, |
| 217 | + ]; |
| 218 | + }; |
145 | 219 | }
|
146 | 220 |
|
147 | 221 | make() {
|
@@ -210,49 +284,77 @@ export class NegativeProductionExternalityIndustryGraph extends Graph {
|
210 | 284 | me.options.gA5, me.options.gA6, x);
|
211 | 285 | };
|
212 | 286 |
|
213 |
| - this.l4 = this.board.create( |
214 |
| - 'functiongraph', |
215 |
| - [positiveRange(smc2Line), 0, this.options.gXAxisMax], { |
216 |
| - name: 'SMC', |
217 |
| - withLabel: true, |
218 |
| - label: { |
219 |
| - strokeColor: this.l4Color |
220 |
| - }, |
221 |
| - strokeWidth: 2, |
222 |
| - strokeColor: this.l4Color, |
223 |
| - fixed: true, |
224 |
| - highlight: false |
225 |
| - } |
226 |
| - ); |
| 287 | + if (this.options.gFunctionChoice === 0) { |
| 288 | + this.l4 = this.board.create( |
| 289 | + 'functiongraph', |
| 290 | + [positiveRange(smc2Line), 0, this.options.gXAxisMax], { |
| 291 | + name: 'SMC', |
| 292 | + withLabel: true, |
| 293 | + label: { |
| 294 | + strokeColor: this.l4Color |
| 295 | + }, |
| 296 | + strokeWidth: 2, |
| 297 | + strokeColor: this.l4Color, |
| 298 | + fixed: true, |
| 299 | + highlight: false |
| 300 | + } |
| 301 | + ); |
| 302 | + } |
| 303 | + |
| 304 | + const epointEvaluated = epoint2( |
| 305 | + this.options.gA1, this.options.gA2, this.options.gA3, |
| 306 | + this.options.gA4); |
| 307 | + |
| 308 | + if (this.options.gFunctionChoice === 1) { |
| 309 | + const mcYZero = mc2(this.options.gA3, this.options.gA4, 0); |
| 310 | + drawPolygon( |
| 311 | + this.board, [ |
| 312 | + epointEvaluated, |
| 313 | + [0, epointEvaluated[1]], |
| 314 | + [0, mcYZero] |
| 315 | + ], null, 'orange' |
| 316 | + ); |
| 317 | + |
| 318 | + const emcYPoint = emc2( |
| 319 | + this.options.gA5, this.options.gA6, epointEvaluated[0]); |
| 320 | + const emcYZero = emc2(this.options.gA5, this.options.gA6, 0); |
| 321 | + |
| 322 | + drawPolygon( |
| 323 | + this.board, [ |
| 324 | + [epointEvaluated[0], emcYPoint], |
| 325 | + [epointEvaluated[0], 0], |
| 326 | + [0, 0], |
| 327 | + [0, emcYZero], |
| 328 | + ], null, 'red' |
| 329 | + ); |
| 330 | + } |
227 | 331 |
|
228 | 332 | if (this.options.gShowIntersection) {
|
229 | 333 | const spointEvaluated = spoint2(
|
230 | 334 | this.options.gA1, this.options.gA2, this.options.gA3,
|
231 | 335 | this.options.gA4, this.options.gA5, this.options.gA6);
|
232 | 336 |
|
233 |
| - this.showIntersection( |
234 |
| - this.board.create('line', [ |
235 |
| - shint2( |
236 |
| - this.options.gA1, this.options.gA2, this.options.gA3, |
237 |
| - this.options.gA4, this.options.gA5, this.options.gA6), |
238 |
| - spointEvaluated |
239 |
| - ], { |
240 |
| - visible: false |
241 |
| - }), |
242 |
| - this.board.create('line', [ |
243 |
| - svint2( |
244 |
| - this.options.gA1, this.options.gA2, this.options.gA3, |
245 |
| - this.options.gA4, this.options.gA5, this.options.gA6), |
246 |
| - spointEvaluated |
247 |
| - ], { |
248 |
| - visible: false |
249 |
| - }), |
250 |
| - false, 'Social', null, 'Q<sup>soc</sup>', |
251 |
| - false, false, this.l1Color); |
252 |
| - |
253 |
| - const epointEvaluated = epoint2( |
254 |
| - this.options.gA1, this.options.gA2, this.options.gA3, |
255 |
| - this.options.gA4); |
| 337 | + if (this.options.gFunctionChoice === 0) { |
| 338 | + this.showIntersection( |
| 339 | + this.board.create('line', [ |
| 340 | + shint2( |
| 341 | + this.options.gA1, this.options.gA2, this.options.gA3, |
| 342 | + this.options.gA4, this.options.gA5, this.options.gA6), |
| 343 | + spointEvaluated |
| 344 | + ], { |
| 345 | + visible: false |
| 346 | + }), |
| 347 | + this.board.create('line', [ |
| 348 | + svint2( |
| 349 | + this.options.gA1, this.options.gA2, this.options.gA3, |
| 350 | + this.options.gA4, this.options.gA5, this.options.gA6), |
| 351 | + spointEvaluated |
| 352 | + ], { |
| 353 | + visible: false |
| 354 | + }), |
| 355 | + false, 'Social', null, 'Q<sup>soc</sup>', |
| 356 | + false, false, this.l1Color); |
| 357 | + } |
256 | 358 |
|
257 | 359 | this.showIntersection(
|
258 | 360 | this.board.create('line', [
|
|
0 commit comments