Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed Mar 5, 2025
1 parent 6ea62c8 commit 093e0a3
Show file tree
Hide file tree
Showing 2 changed files with 281 additions and 1 deletion.
191 changes: 191 additions & 0 deletions media/js/src/editors/NegativeProductionExternalityProducerEditor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import React from 'react';
import PropTypes from 'prop-types';
import RangeEditor from '../form-components/RangeEditor.jsx';
import { handleFormUpdate } from '../utils.js';

export default class NegativeProductionExternalityProducerEditor extends React.Component {
render() {
const me = this;

const modesLeft = [
'Negative Producer Externality',
'Unregulated',
'Welfare',
];
const modesRight = [
'Pigouvian Tax',
'Pigouvian Tax (Welfare)',
];

const radioButtons1 = modesLeft.map((optionTitle, idx) =>
<div key={idx} className="form-check">
<input
type="radio" id={`functionChoice-${idx}`}
className="form-check-input"
value={idx}
name="gFunctionChoice"
checked={me.props.gFunctionChoice === idx}
onChange={handleFormUpdate.bind(me)} />
<label
className="form-check-label"
htmlFor={`functionChoice-${idx}`}>
{optionTitle}
</label>
</div>
);

const radioButtons2 = modesRight.map(function(optionTitle, idx) {
const newIdx = idx + modesLeft.length;
return (
<div key={newIdx} className="form-check">
<input
type="radio" id={`functionChoice-${newIdx}`}
className="form-check-input"
value={newIdx}
name="gFunctionChoice"
checked={me.props.gFunctionChoice === newIdx}
onChange={handleFormUpdate.bind(me)} />
<label
className="form-check-label"
htmlFor={`functionChoice-${newIdx}`}>
{optionTitle}
</label>
</div>
);
});

return (
<>
<div className="row">
<div className="col">
{radioButtons1}
</div>
<div className="col">
{radioButtons2}
</div>
</div>

<div>
{this.props.displaySliders && (
<>
<RangeEditor
label="Choke Price"
rawLabel={true}
id="gA1"
value={this.props.gA1}
min={0}
max={10000}
handler={handleFormUpdate.bind(this)} />

<RangeEditor
label="Demand Slope"
rawLabel={true}
id="gA2"
value={this.props.gA2}
min={0.01}
max={35}
handler={handleFormUpdate.bind(this)} />

<RangeEditor
label="Reservation Price"
rawLabel={true}
id="gA3"
value={this.props.gA3}
min={0}
max={10000}
handler={handleFormUpdate.bind(this)} />

<RangeEditor
label="Supply Slope"
rawLabel={true}
id="gA4"
value={this.props.gA4}
min={0.01}
max={35}
handler={handleFormUpdate.bind(this)} />
</>
)}
{(
this.props.gFunctionChoice === 2 ||
this.props.gFunctionChoice === 3
) && (
<RangeEditor
label="Global Price"
rawLabel={true}
id="gA5"
value={this.props.gA5}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
{(this.props.gFunctionChoice === 3) && (
<RangeEditor
label="Tariff"
rawLabel={true}
id="gA6"
value={this.props.gA6}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
{(this.props.gFunctionChoice === 4 || this.props.gFunctionChoice === 5) && (
<RangeEditor
label="Global Price"
rawLabel={true}
id="gA5"
value={this.props.gA5}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
{(this.props.gFunctionChoice === 6 || this.props.gFunctionChoice === 8) && (
<RangeEditor
label="Minimum Price"
rawLabel={true}
id="gA5"
value={this.props.gA5}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
{(this.props.gFunctionChoice === 7 || this.props.gFunctionChoice === 9) && (
<RangeEditor
label="Maximum Price"
rawLabel={true}
id="gA5"
value={this.props.gA5}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
{(this.props.gFunctionChoice === 10 || this.props.gFunctionChoice === 11) && (
<RangeEditor
label="Production Quota"
rawLabel={true}
id="gA5"
value={this.props.gA5}
min={0}
max={this.props.gA1}
handler={handleFormUpdate.bind(this)} />
)}
</div>
</>
);
}
}

NegativeProductionExternalityProducerEditor.propTypes = {
gType: PropTypes.number.isRequired,

gA1: PropTypes.number.isRequired,
gA2: PropTypes.number.isRequired,
gA3: PropTypes.number.isRequired,
gA4: PropTypes.number.isRequired,
gA5: PropTypes.number,
gA6: PropTypes.number,

gFunctionChoice: PropTypes.number.isRequired,
gToggle: PropTypes.bool.isRequired,

displaySliders: PropTypes.bool.isRequired
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,95 @@
import {Graph} from './Graph.js';
import {Graph, positiveRange} from './Graph.js';

export const defaults = [
{
gXAxisMax: 1000,
gYAxisMax: 2500,
gA1: 500,
gA2: 2,
gA3: 50,
gA4: 2,
}
];

// Marginal Benefit
const mb = function(a) {

Check failure on line 15 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'mb' is assigned a value but never used
return a;
};

const mc = function(c, d, q) {
return c + d * q;
};

// External Marginal Cost
const emc = function(f, g, q) {
return f + g * q;
};

const pemc = function(f, g, p) {

Check failure on line 28 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'pemc' is assigned a value but never used
return (p - f) / g;
};


// Social Marginal Cost
const smc = function(c, d, f, g, q) {

Check failure on line 34 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'smc' is assigned a value but never used
return mc(c, d, q) + emc(f, g, q);
};

const psmc = function(c, d, f, g, p) {

Check failure on line 38 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'psmc' is assigned a value but never used
return (p - c - f) / (d + g);
};

export class NegativeProductionExternalityProducerGraph extends Graph {
static getGraphPane(gFunctionChoice) {
return [
{
label: 'Unregulated Output q*',
color: 'red',
value: 500
},
{
label: 'Socially Desirable Output q<sup>soc</sup>',
color: 'orange',
value: 247.5
},
{
label: 'Market Price P*',
color: 'red',
value: 1500
},
];
}
make() {
this.l1 = this.board.create(
'functiongraph',
[positiveRange(demandLine), 0, this.options.gXAxisMax], {

Check failure on line 65 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'demandLine' is not defined
name: 'Demand',
withLabel: true,
label: {
strokeColor: this.l1Color
},
strokeWidth: 2,
strokeColor: this.l1Color,
fixed: true,
highlight: false
}
);

this.l2 = this.board.create(
'functiongraph',
[positiveRange(demandLine), 0, this.options.gXAxisMax], {

Check failure on line 80 in media/js/src/graphs/NegativeProductionExternalityProducerGraph.js

View workflow job for this annotation

GitHub Actions / JS tests

'demandLine' is not defined
name: 'Demand',
withLabel: true,
label: {
strokeColor: this.l2Color
},
strokeWidth: 2,
strokeColor: this.l2Color,
fixed: true,
highlight: false
}
);
}
}

export const mkNegativeProductionExternalityProducer = function(board, options) {
Expand Down

0 comments on commit 093e0a3

Please sign in to comment.