Skip to content

Commit 17dafbd

Browse files
committed
Added font face control. More form polish. New example, different size.
1 parent 096a675 commit 17dafbd

File tree

3 files changed

+63
-44
lines changed

3 files changed

+63
-44
lines changed

build/index.html

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,43 @@
2727
</th>
2828
</tr>
2929
<tr>
30-
<td id="flows_entry">
30+
<td id="other_entry">
31+
32+
<p class="ui_head" onclick="toggle('input_options');"><span id="input_options_indicator" class="indicator">&dArr;</span>
33+
Inputs<span id="input_options_hint">:</span></p>
34+
35+
<div id="input_options">
3136
<textarea id="flows_in" rows="22" cols="40" onchange="process_sankey();">' Type a list of Flows, like this:
3237
' SOURCE [AMOUNT] TARGET
3338

34-
' To set a color for one specific Flow, add
35-
' an HTML color code to the end of the line:
36-
' SOURCE [AMOUNT] TARGET #COLOR
37-
3839
' After all your Flows are entered, use
3940
' the controls below to customize the
4041
' diagram's design.
4142

4243
' Examples:
4344

44-
Here [8] Everywhere
45-
There [5.5] Everywhere
46-
Everywhere [6] Over there
47-
Everywhere [5] Somewhere else
48-
Far far away [3] Nearby
49-
Everywhere [2.5] Nearby #55FF00</textarea>
45+
Wages [2000] Budget
46+
Interest [5] Budget
47+
Budget [500] Taxes
48+
Budget [400] Housing
49+
Budget [300] Food
50+
Budget [205] Transportation
51+
Budget [400] Health Care
52+
Budget [200] Other Necessities
5053

51-
<p class="center_basic"><button id="preview_graph" type="submit">Preview</button></p>
54+
' For even finer control over presentation,
55+
' go to the Manual.</textarea>
5256

53-
</td>
54-
</tr>
55-
56-
<tr>
57-
<td id="other_entry">
57+
<p class="center_basic"><button id="preview_graph" type="submit">Preview</button></p>
58+
</div>
5859

5960
<p class="ui_head" onclick="toggle('diagram_options');"><span id="diagram_options_indicator" class="indicator">&uArr;</span>
6061
Diagram options<span id="diagram_options_hint">:</span></p>
6162

6263
<div id="diagram_options" class="form_chunk">
6364
<p class="form_elements1"><strong>Size</strong> (pixels):
64-
<label for="canvas_width">Width =</label> <input type="text" id="canvas_width" size="5" maxlength="6" value="700" onchange="process_sankey();">
65-
<label for="canvas_height">Height =</label> <input type="text" id="canvas_height" size="5" maxlength="6" value="400" onchange="process_sankey();">
65+
<label for="canvas_width">Width =</label> <input type="text" id="canvas_width" size="5" maxlength="6" value="600" onchange="process_sankey();">
66+
<label for="canvas_height">Height =</label> <input type="text" id="canvas_height" size="5" maxlength="6" value="500" onchange="process_sankey();">
6667
</p>
6768

6869
<p class="form_elements2">
@@ -82,15 +83,23 @@
8283
<p class="form_elements1">
8384
<label for="font_size"><strong>Size:</strong></label>
8485
<input type="text" id="font_size" size="2" maxlength="4" value="13" onchange="process_sankey();"> <label for="font_size">px</label>
85-
<label for="font_color" class="spaced_label"><strong>Color:</strong></label>
86-
<input type="color" id="font_color" size="7" maxlength="7" value="#000000" onchange="process_sankey();">
87-
<br />
8886

89-
<label for="font_weight"><strong>Weight:</strong></label> <span style="font-weight: lighter;" class="smalllabel">Light</span><input id="font_weight" type="range" min="100" max="700" step="300" value="400" onchange="process_sankey();" class="narrowslider"><span style="font-weight: bolder;" class="smalllabel">Bold</span>
87+
<strong class="spaced_label">Face:</strong>
88+
<input name="font_face" type="radio" id="sans_serif" value="sans-serif" checked="checked" onchange="process_sankey();" /><label for="sans_serif" style="font-family: sans-serif;">sans</label>
89+
<input name="font_face" type="radio" id="serif" value="serif" onchange="process_sankey();" /><label for="serif" style="font-family: serif;">serif</label>
90+
<input name="font_face" type="radio" id="monospace" value="monospace" onchange="process_sankey();" /><label for="monospace" style="font-family: monospace;">mono</label>
9091
</p>
9192

9293
<p class="form_elements2">
93-
<strong>Units:</strong> <label for="unit_prefix">Prefix =</label> <input type="text" id="unit_prefix" size="3" maxlength="10" onchange="process_sankey();">
94+
<label for="font_color"><strong>Color:</strong></label>
95+
<input type="color" id="font_color" size="7" maxlength="7" value="#000000" onchange="process_sankey();">
96+
97+
<label for="font_weight" class="spaced_label"><strong>Weight:</strong></label>
98+
<span style="font-weight: lighter;" class="smalllabel">Light</span><input id="font_weight" type="range" min="100" max="700" step="300" value="400" onchange="process_sankey();" class="narrowslider"><span style="font-weight: bolder;" class="smalllabel">Bold</span><br />
99+
</p>
100+
101+
<p class="form_elements1">
102+
<strong>Units:</strong> <label for="unit_prefix">Prefix =</label> <input type="text" id="unit_prefix" size="3" maxlength="10" value="$" onchange="process_sankey();">
94103
<label for="unit_suffix">Suffix =</label> <input type="text" id="unit_suffix" size="5" maxlength="10" onchange="process_sankey();"><br />
95104

96105
&nbsp; <input type="checkbox" id="include_values_in_node_labels" value="1" onchange="process_sankey();" checked="checked">
@@ -120,7 +129,7 @@
120129
</p>
121130

122131
<p class="form_elements2">
123-
<label for="default_flow_opacity"><strong>Default Flow Opacity:</strong></label>
132+
<label for="default_flow_opacity"><strong>Default Opacity:</strong></label>
124133
<span class="smalllabel">0.0</span><input id="default_flow_opacity" type="range" min="0" max="1" step="0.1" value="0.4" onchange="process_sankey();" class="narrowslider"><span class="smalllabel">1.0</span>
125134
</p>
126135
</div>
@@ -132,8 +141,8 @@
132141
<p class="form_elements1">
133142
<strong>Colors:</strong>
134143
Use from assortment:
135-
<input name="default_node_colorset" type="radio" id="node_use_set_a" value="A" onchange="process_sankey();" /><label for="node_use_set_a">A</label>
136-
<input name="default_node_colorset" type="radio" id="node_use_set_b" value="B" onchange="process_sankey();" checked="checked" /><label for="node_use_set_b">B</label>
144+
<input name="default_node_colorset" type="radio" id="node_use_set_a" value="A" onchange="process_sankey();" checked="checked" /><label for="node_use_set_a">A</label>
145+
<input name="default_node_colorset" type="radio" id="node_use_set_b" value="B" onchange="process_sankey();" /><label for="node_use_set_b">B</label>
137146
<input name="default_node_colorset" type="radio" id="node_use_set_c" value="C" onchange="process_sankey();" /><label for="node_use_set_c">C</label><br />
138147
<input name="default_node_colorset" type="radio" id="node_use_color" value="none" onchange="process_sankey();" /><label for="node_use_color">Use one color:</label>
139148
<input type="color" id="default_node_color" size="7" maxlength="7" value="#006699" onchange="process_sankey();"><br />
@@ -224,9 +233,9 @@
224233
</table>
225234

226235
<p id="chart">
227-
<svg id="the_svg" height="400" width="700" xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>
236+
<svg id="the_svg" height="500" width="600" xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>
228237
</p>
229-
<canvas id="png_preview" height="400" width="700" style="background: #FFFFFF; display:none;"></canvas>
238+
<canvas id="png_preview" height="500" width="600" style="background: #FFFFFF; display:none;"></canvas>
230239
<div id="chartfooter">
231240
</div>
232241
</td></tr></table>

build/main.css

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ textarea#flows_in {
8383
}
8484

8585
/* label which needs leftward breathing room:*/
86-
.spaced_label { margin-left: 15px; }
86+
.spaced_label { margin-left: 12px; }
8787

8888
.ui_head {
8989
font-size: 14px;
9090
padding: 3px 6px 2px;
9191
margin: 2px 0px 0px;
9292
background-color: #004477;
9393
color: white;
94+
text-align: left;
9495
}
9596
.ui_head:hover {
9697
background-color: #006699;
@@ -107,8 +108,8 @@ textarea#flows_in {
107108
}
108109

109110
p#chart {
110-
width: 700px;
111-
height: 400px;
111+
width: 600px;
112+
height: 500px;
112113
border: 1px dotted #666666;
113114
margin: 10px auto;
114115
background-color: white;
@@ -131,8 +132,9 @@ p#chart {
131132
td { vertical-align: top; padding: 2px;}
132133

133134
td#other_entry {
134-
padding: 2px;
135+
padding: 0px 2px;
135136
background-color: #CCE8FF;
137+
vertical-align: middle;
136138
}
137139

138140
td#grapharea {
@@ -149,11 +151,14 @@ th#title {
149151
font-size: large;
150152
}
151153

154+
div#input_options {
155+
text-align: center;
156+
}
157+
152158
td#flows_entry {
153-
padding: 2px;
159+
padding: 0px 2px;
154160
background-color: #BBDDEE;
155161
text-align: center;
156-
padding: 5px;
157162
vertical-align: middle;
158163
}
159164

build/sankeymatic.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function process_sankey() {
108108
svg_content = '', canvas_el = '', chart_el = '',
109109
png_link_el = '', reverse_the_graph = 0,
110110
max_node_index = 0, max_node_val = 0, flow_inherit = '',
111-
colorset = '',
111+
colorset_in = '', fontface_in = '',
112112
messages_el = document.getElementById("messages_area"),
113113
png_link_el = document.getElementById("download_png"),
114114
canvas_el = document.getElementById("png_preview"),
@@ -371,8 +371,8 @@ function process_sankey() {
371371
display_full_precision: 0,
372372
include_values_in_node_labels: 0,
373373
hide_labels: 0,
374-
canvas_width: 700,
375-
canvas_height: 400,
374+
canvas_width: 600,
375+
canvas_height: 500,
376376
font_size: 13,
377377
font_weight: 400,
378378
top_margin: 12, right_margin: 12, bottom_margin: 12, left_margin: 12,
@@ -387,7 +387,8 @@ function process_sankey() {
387387
background_color: "#FFFFFF",
388388
font_color: "#000000",
389389
default_node_color: "#006699",
390-
default_node_colorset: "B"
390+
default_node_colorset: "A",
391+
font_face: "sans-serif"
391392
};
392393

393394
// Plain strings:
@@ -447,9 +448,13 @@ function process_sankey() {
447448
get_color_input(field_name);
448449
});
449450

450-
colorset = radio_value("default_node_colorset");
451-
if ( colorset.match( /^(?:[ABC]|none)$/ ) ) {
452-
approved_config.default_node_colorset = colorset;
451+
colorset_in = radio_value("default_node_colorset");
452+
if ( colorset_in.match( /^(?:[ABC]|none)$/ ) ) {
453+
approved_config.default_node_colorset = colorset_in;
454+
}
455+
fontface_in = radio_value("font_face");
456+
if ( fontface_in.match( /^(?:serif|sans\-serif|monospace)$/ ) ) {
457+
approved_config.font_face = fontface_in;
453458
}
454459

455460
// Checkboxes:
@@ -642,7 +647,7 @@ function render_sankey(nodes_in, flows_in, config_in) {
642647
// clear out any old contents:
643648
// Simply emptying the SVG tag didn't work well in Safari; we reset the whole tag here:
644649
document.getElementById('chart').innerHTML =
645-
'<svg id="the_svg" height="400" width="700" xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>';
650+
'<svg id="the_svg" height="500" width="600" xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>';
646651

647652
// Select the svg canvas, set the defined dimensions:
648653
svg = d3.select("#the_svg")
@@ -779,8 +784,8 @@ function render_sankey(nodes_in, flows_in, config_in) {
779784
: "" );
780785
})
781786
.style( { // be explicit about the font specs:
782-
"font-family": "helvetica, sans-serif",
783787
"stroke-width": "0", // positive stroke-width makes letters fuzzy
788+
"font-family": config_in.font_face,
784789
"font-size": config_in.font_size + "px",
785790
"font-weight": config_in.font_weight,
786791
"fill": config_in.font_color

0 commit comments

Comments
 (0)