Skip to content

Commit 32a8386

Browse files
committed
simplify: don't recreate JSON
1 parent 2b0d031 commit 32a8386

10 files changed

Lines changed: 21 additions & 479 deletions

File tree

common/viewUtils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from visualizer.descriptors.textForWinnerUtils import as_caption
1111
from visualizer.graph.graphCreator import make_graph_with_file
1212
from visualizer.models import TextForWinner
13-
from visualizer.pie.graphToRCtab import graph_to_rctab_json
1413
from visualizer.sankey.graphToD3 import D3Sankey
1514
from visualizer.sidecar.reader import SidecarReader
1615
from visualizer.tabular.tabular import TabulateByRoundInteractive, \
@@ -69,8 +68,7 @@ def get_data_for_graph(graph, config):
6968
'tabularByRound': tabularByRound,
7069
'tabularByRoundInteractive': tabularByRoundInteractive,
7170
'graph': graph,
72-
'rawData': graph._raw_JSON,
73-
'pieData': graph_to_rctab_json(graph),
71+
'pieData': graph.get_migrated_raw_data(),
7472
'textForWinner': as_caption(config).lower(),
7573
}
7674
roundDescriberData = get_data_for_round_describer(graph, config)

rcvis/settings.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,6 @@
193193
}
194194

195195

196-
def pie_chart_no_cache(headers, path, url):
197-
"""In development, ensure browsers revalidate the pie chart component on every load."""
198-
if DEBUG and url.endswith('pie-chart.es.js'):
199-
headers['Cache-Control'] = 'no-cache'
200-
201-
202-
WHITENOISE_ADD_HEADERS_FUNCTION = pie_chart_no_cache
203-
204196
NODE_PACKAGE_JSON = './package.json'
205197
NODE_MODULES_ROOT = './node_modules'
206198
NODE_PACKAGE_MANAGER_EXECUTABLE = os.environ.get('NODE_PACKAGE_MANAGER_EXECUTABLE', '/usr/bin/npm')

static/visualizer/round-player.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ function RoundPlayer({
44
onPlay,
55
totalRounds,
66
timeBetweenStepsMs,
7+
firstStepHoldTimeMs,
78
}) {
89
let isPlaying = false;
910
let currentStep = totalRounds - 1;
1011
// Imported from visualize-common.js
1112
let stepTimeMs =
1213
timeBetweenStepsMs || getTimeBetweenAnimationStepsMs(totalRounds);
14+
let firstStepTimeMs = firstStepHoldTimeMs || stepTimeMs;
1315
let timer = null;
1416
const svgNS = "http://www.w3.org/2000/svg";
1517
const MIN_ROUNDS_FOR_NAV = 3;
@@ -132,21 +134,21 @@ function RoundPlayer({
132134
changeStep(step);
133135
}
134136

135-
function nextStep() {
137+
function nextStep(currStepTimeMs) {
136138
if (!isPlaying) return;
137139

138140
timer = window.setTimeout(() => {
139141
changeStep(currentStep + 1);
140-
nextStep();
141-
}, stepTimeMs);
142+
nextStep(stepTimeMs);
143+
}, currStepTimeMs);
142144
}
143145

144146
function play() {
145147
if (onPlay) onPlay();
146148
isPlaying = true;
147149
container.querySelector(".round-player-play-btn").innerText = "Stop";
148150
changeStep(0);
149-
nextStep();
151+
nextStep(firstStepTimeMs);
150152
}
151153

152154
function stop() {

templates/pie/pie-nonblocking.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
totalRounds: {{ config.numRounds }},
4444
onChange: updatePieChartRound,
4545
timeBetweenStepsMs: 3000,
46+
firstStepHoldTimeMs: 500,
4647
});
4748

4849
function updatePieChartRound(sliderIndex) {

visualizer/common.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ def percentify(numerator, denominator):
3434
return str(round(10000.0 * floatVal) / 100.0) + "%"
3535

3636

37-
def stringify(value):
38-
""" Convert a number to string, matching RCTab JSON convention.
39-
Integers are formatted without decimals. """
40-
if isinstance(value, float) and value == int(value):
41-
return str(int(value))
42-
return str(value)
43-
44-
4537
def candidate_renames():
4638
""" A dictionary mapping how we should rename candidate names """
4739
return {

visualizer/graph/graph.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def set_elimination_order(self, orderedCandidates):
9797
# Reset summary: it's no longer accurate
9898
self.summary = None
9999

100+
def set_migrated_raw_data(self, migratedRawData):
101+
""" As of implementation, only used for pie chart visualization. """
102+
self.migratedRawData = migratedRawData
103+
104+
def get_migrated_raw_data(self):
105+
""" As of implementation, only used for pie chart visualization. """
106+
return self.migratedRawData
107+
100108
def set_date(self, date):
101109
""" Sets the date of this election """
102110
assert isinstance(date, datetime.datetime)

visualizer/graph/readRCVRCJSON.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ class JSONReader:
271271
eliminationOrder: list
272272

273273
def __init__(self, data):
274-
self.parse_data(data)
274+
data = self.parse_and_migrate_data(data)
275275
self.graph.create_graph_from_rounds(self.rounds)
276+
self.graph.set_migrated_raw_data(data)
276277
self.set_elimination_order(self.rounds, self.graph.candidates)
277-
self.graph._raw_JSON = data
278278

279-
def parse_data(self, data):
279+
def parse_and_migrate_data(self, data):
280280
""" Parses the JSON data, or raises an exception on failure """
281281
def get_migration_tasks():
282282
return [FixNoTransfersTask,
@@ -362,6 +362,7 @@ def load_rounds(data):
362362

363363
self.graph = graph
364364
self.rounds = rounds
365+
return data
365366

366367
def get_graph(self):
367368
""" Returns the Graph object """
@@ -370,7 +371,7 @@ def get_graph(self):
370371
def get_rounds(self):
371372
""" Returns the list of rounds """
372373
return self.rounds
373-
374+
374375
def set_elimination_order(self, rounds, candidates):
375376
""" Sets the elimination order given each round and a list of Candidates """
376377
eliminationOrder = []

visualizer/pie/__init__.py

Whitespace-only changes.

visualizer/pie/graphToRCtab.py

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)