Skip to content

Commit 224a7ed

Browse files
committed
NPE Industry graph: Implement scenario 2: "Unregulated"
1 parent 74d2315 commit 224a7ed

File tree

1 file changed

+167
-65
lines changed

1 file changed

+167
-65
lines changed

media/js/src/graphs/NegativeProductionExternalityIndustryGraph.js

+167-65
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Graph, positiveRange } from './Graph.js';
2+
import { drawPolygon } from '../jsxgraphUtils.js';
23

34
export const defaults = [
45
{
@@ -81,17 +82,17 @@ const sq2 = function(a, b, c, d, f, g) {
8182
return (a - c - f) / (b + d + g);
8283
};
8384

84-
/*const psurplus2 = function(a, b, c, d) {
85+
const psurplus2 = function(a, b, c, d) {
8586
return (ep2(a, b, c, d) - c) * eq2(a, b, c, d) / 2;
86-
};*/
87+
};
8788

88-
/*const emcmarket2 = function(a, b, c, d, f, g) {
89+
const emcmarket2 = function(a, b, c, d, f, g) {
8990
return f + g * eq2(a, b, c, d);
90-
};*/
91+
};
9192

92-
/*const extcost2 = function(a, b, c, d, f, g) {
93+
const extcost2 = function(a, b, c, d, f, g) {
9394
return emcmarket2(a, b, c, d, f, g) * eq2(a, b, c, d) / 2;
94-
};*/
95+
};
9596

9697
const spoint2 = function(a, b, c, d, f, g) {
9798
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) {
120121

121122
export class NegativeProductionExternalityIndustryGraph extends Graph {
122123
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+
};
145219
}
146220

147221
make() {
@@ -210,49 +284,77 @@ export class NegativeProductionExternalityIndustryGraph extends Graph {
210284
me.options.gA5, me.options.gA6, x);
211285
};
212286

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+
}
227331

228332
if (this.options.gShowIntersection) {
229333
const spointEvaluated = spoint2(
230334
this.options.gA1, this.options.gA2, this.options.gA3,
231335
this.options.gA4, this.options.gA5, this.options.gA6);
232336

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+
}
256358

257359
this.showIntersection(
258360
this.board.create('line', [

0 commit comments

Comments
 (0)