Last active
August 28, 2016 23:42
-
-
Save rleddy/dd42ab598f5269538e8f3f8b1c66f8d2 to your computer and use it in GitHub Desktop.
This is a further development of the previous gists. The date picker is improved a little. Also, you can select a window and load a colorful pure SVG form into the window. It has check boxes and radio buttons. An editable field has been borrowed and integrated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<g id="g-app-icecream"> | |
<g | |
id="g4857" | |
transform="translate(-29.041886,-35.860416)"> | |
<g | |
id="g-app-flavor"> | |
<rect | |
style="opacity:1;fill:#ffffe7;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.30572197;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="rect4840" | |
width="129.04126" | |
height="96.211311" | |
x="29.549824" | |
y="36.40414" /> | |
<g | |
id="g-sel-1" | |
transform="translate(0,2.9162922e-5)"> | |
<circle class="svg-checkbox" | |
r="13.167804" | |
cy="55.089104" | |
cx="48.931602" | |
id="path4795" | |
style="opacity:1;fill:#08e7db;fill-opacity:0.94267518;stroke:#dd4a61;stroke-width:0.22835846;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<path class="svg-checkbox-sel" | |
transform="matrix(0.26106728,0.005013,-0.00486265,0.25323731,27.483597,30.944538)" | |
d="m 132.85714,76.647922 -23.99037,24.452088 6.73217,33.58751 -30.668756,-15.26009 -29.863262,16.78178 5.036043,-33.88334 -25.18868,-23.215797 33.781197,-5.680967 14.295802,-31.129933 15.841885,30.372312 z" | |
id="sel-1" | |
style="visibility:hidden;opacity:1;fill:#9c3094;fill-opacity:0.94267518;stroke:#9413e2;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<text | |
id="text-sel-1" | |
y="58.387638" | |
x="71.215752" | |
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
xml:space="preserve"><tspan | |
y="58.387638" | |
x="71.215752" | |
id="tspan4793">Chocolate</tspan></text> | |
</g> | |
<g | |
id="g-sel-2" | |
transform="translate(0,29.000029)"> | |
<circle class="svg-checkbox" | |
style="opacity:1;fill:#08e7db;fill-opacity:0.94267518;stroke:#dd4a61;stroke-width:0.22835846;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="circle4805" | |
cx="48.931602" | |
cy="55.089104" | |
r="13.167804" /> | |
<path class="svg-checkbox-sel" | |
style="visibility:hidden;opacity:1;fill:#9c3094;fill-opacity:0.94267518;stroke:#9413e2;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="sel-2" | |
d="m 132.85714,76.647922 -23.99037,24.452088 6.73217,33.58751 -30.668756,-15.26009 -29.863262,16.78178 5.036043,-33.88334 -25.18868,-23.215797 33.781197,-5.680967 14.295802,-31.129933 15.841885,30.372312 z" | |
transform="matrix(0.26106728,0.005013,-0.00486265,0.25323731,27.483597,30.944538)" /> | |
<text | |
xml:space="preserve" | |
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
x="71.215752" | |
y="58.387638" | |
id="text-sel-2"><tspan | |
id="tspan4811" | |
x="71.215752" | |
y="58.387638">Vanilla</tspan></text> | |
</g> | |
<g | |
transform="translate(0,58.000029)" | |
id="g-sel-3"> | |
<circle class="svg-checkbox" | |
r="13.167804" | |
cy="55.089104" | |
cx="48.931602" | |
id="circle4815" | |
style="opacity:1;fill:#08e7db;fill-opacity:0.94267518;stroke:#dd4a61;stroke-width:0.22835846;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<path class="svg-checkbox-sel" | |
transform="matrix(0.26106728,0.005013,-0.00486265,0.25323731,27.483597,30.944538)" | |
d="m 132.85714,76.647922 -23.99037,24.452088 6.73217,33.58751 -30.668756,-15.26009 -29.863262,16.78178 5.036043,-33.88334 -25.18868,-23.215797 33.781197,-5.680967 14.295802,-31.129933 15.841885,30.372312 z" | |
id="sel-3" | |
style="visibility:hidden;opacity:1;fill:#9c3094;fill-opacity:0.94267518;stroke:#9413e2;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<text | |
id="text-sel-3" | |
y="58.387638" | |
x="71.215752" | |
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
xml:space="preserve"><tspan | |
y="58.387638" | |
x="71.215752" | |
id="tspan4821">Strawberry</tspan></text> | |
</g> | |
</g> | |
<g | |
id="g-sel-container"> | |
<rect | |
y="36.647545" | |
x="159.34531" | |
height="95.977043" | |
width="113.65471" | |
id="rect5021" | |
style="opacity:1;fill:#ebffdc;fill-opacity:1;stroke:#dd944a;stroke-width:0.28745195;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<g | |
transform="translate(-53.791127,-52.742409)" | |
id="g5023"> | |
<g | |
id="g-rad-1" | |
transform="translate(30.809652,47.982183)"> | |
<g | |
transform="translate(0,12.204258)" | |
id="g4924"> | |
<circle class="svg-radiobutton-off" | |
style="opacity:1;fill:#c3f776;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="path4893" | |
cx="198.24243" | |
cy="48.77565" | |
r="6.0609155" /> | |
<circle class="svg-radiobutton-on" | |
r="4.0894027" | |
cy="48.77565" | |
cx="198.24243" | |
id="rad-1" | |
style="visibility:hidden;opacity:1;fill:#780b11;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.20241511;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
</g> | |
<text | |
id="rad-text-1" | |
y="65.123764" | |
x="209.85918" | |
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:15px;line-height:125%;font-family:Optima;-inkscape-font-specification:'Optima, Bold Italic';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#924f0a;fill-opacity:1;stroke:#dd944a;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
xml:space="preserve"><tspan | |
y="65.123764" | |
x="209.85918" | |
id="tspan4910">waffle cone</tspan></text> | |
</g> | |
<g | |
id="g-rad-2" | |
transform="translate(30.809652,66.64887)"> | |
<g | |
id="g4937" | |
transform="translate(0,12.204258)"> | |
<circle class="svg-radiobutton-off" | |
r="6.0609155" | |
cy="48.77565" | |
cx="198.24243" | |
id="circle4939" | |
style="opacity:1;fill:#c3f776;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<circle class="svg-radiobutton-on" | |
style="visibility:hidden;opacity:1;fill:#780b11;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.20241511;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="rad-2" | |
cx="198.24243" | |
cy="48.77565" | |
r="4.0894027" /> | |
</g> | |
<text | |
xml:space="preserve" | |
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:15px;line-height:125%;font-family:Optima;-inkscape-font-specification:'Optima, Bold Italic';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#924f0a;fill-opacity:1;stroke:#dd944a;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
x="209.85918" | |
y="65.123764" | |
id="text4943"><tspan | |
id="tspan4945" | |
x="209.85918" | |
y="65.123764">sugar cone</tspan></text> | |
</g> | |
<g | |
transform="translate(30.809652,85.315557)" | |
id="g-rad-3"> | |
<g | |
transform="translate(0,12.204258)" | |
id="g4949"> | |
<circle class="svg-radiobutton-off" | |
style="opacity:1;fill:#c3f776;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="circle4951" | |
cx="198.24243" | |
cy="48.77565" | |
r="6.0609155" /> | |
<circle class="svg-radiobutton-on" | |
r="4.0894027" | |
cy="48.77565" | |
cx="198.24243" | |
id="rad-3" | |
style="visibility:hidden;opacity:1;fill:#780b11;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.20241511;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
</g> | |
<text | |
id="text4955" | |
y="65.123764" | |
x="209.85918" | |
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:15px;line-height:125%;font-family:Optima;-inkscape-font-specification:'Optima, Bold Italic';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#924f0a;fill-opacity:1;stroke:#dd944a;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
xml:space="preserve"><tspan | |
y="65.123764" | |
x="209.85918" | |
id="tspan4957">waffle cup</tspan></text> | |
</g> | |
<g | |
id="g-rad-4" | |
transform="translate(30.809652,103.98224)"> | |
<g | |
id="g4961" | |
transform="translate(0,12.204258)"> | |
<circle class="svg-radiobutton-off" | |
r="6.0609155" | |
cy="48.77565" | |
cx="198.24243" | |
id="circle4963" | |
style="opacity:1;fill:#c3f776;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.30000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<circle class="svg-radiobutton-on" | |
style="visibility:hidden;opacity:1;fill:#780b11;fill-opacity:0.95833333;stroke:#dd4a61;stroke-width:0.20241511;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
id="rad-4" | |
cx="198.24243" | |
cy="48.77565" | |
r="4.0894027" /> | |
</g> | |
<text | |
xml:space="preserve" | |
style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:15px;line-height:125%;font-family:Optima;-inkscape-font-specification:'Optima, Bold Italic';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#924f0a;fill-opacity:1;stroke:#dd944a;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
x="209.85918" | |
y="65.123764" | |
id="text4967"><tspan | |
id="tspan4969" | |
x="209.85918" | |
y="65.123764">regular cup</tspan></text> | |
</g> | |
</g> | |
</g> | |
</g> | |
<text | |
xml:space="preserve" | |
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12.67170715px;line-height:125%;font-family:Papyrus;-inkscape-font-specification:'Papyrus, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" | |
x="5.5811491" | |
y="134.70087" | |
id="text5077" | |
transform="scale(1.1837351,0.84478361)"><tspan | |
id="tspan5079" | |
x="5.5811491" | |
y="134.70087">Enter e-mail:</tspan></text> | |
<g | |
transform="translate(-4,0)" | |
id="text-edit-group-1"> | |
<rect | |
y="99.788353" | |
x="100.0051" | |
height="18.182749" | |
width="146.9772" | |
id="rect5081" | |
style="opacity:1;fill:#fff2dc;fill-opacity:1;stroke:#605811;stroke-width:2.0999999;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<rect | |
y="101.54778" | |
x="101.25945" | |
height="15.16901" | |
width="144.97362" | |
id="backing-rect" | |
style="opacity:1;fill:#fffaf2;fill-opacity:1;stroke:#bdac19;stroke-width:0.72510022;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> | |
<text | |
xml:space="preserve" | |
contentEditable="true" | |
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11.3941555px;line-height:50%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Italic';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" | |
x="112.49609" | |
y="104.51588" | |
id="flavs-email" | |
transform="scale(0.91509761,1.0927796)">------------------------</text> | |
</g> | |
</g> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
path { | |
pointer-events: all; | |
fill: none; | |
stroke: #666; | |
stroke-opacity: 0.2; | |
} | |
.active square { | |
stroke: #000; | |
stroke-width: 2px; | |
} | |
html, body { margin:0; padding:0; overflow:hidden } | |
</style> | |
<style> | |
.ticks { | |
font: 10px sans-serif; | |
} | |
.track, | |
.track-inset, | |
.track-overlay { | |
stroke-linecap: round; | |
} | |
.track { | |
stroke: #000; | |
stroke-opacity: 0.3; | |
stroke-width: 10px; | |
} | |
.track-inset { | |
stroke: #ddd; | |
stroke-width: 8px; | |
} | |
.track-overlay { | |
pointer-events: stroke; | |
stroke-width: 50px; | |
cursor: crosshair; | |
} | |
.handle { | |
fill: #fff; | |
stroke: #000; | |
stroke-opacity: 0.5; | |
stroke-width: 1.25px; | |
} | |
</style> | |
<style> | |
.svg-checkbox { | |
cursor : pointer; | |
} | |
.svg-checkbox-sel{ | |
cursor : pointer; | |
} | |
.svg-radiobutton-on { | |
cursor : pointer; | |
} | |
.svg-radiobutton-off { | |
cursor : pointer; | |
} | |
</style> | |
<svg id="mainsvg" width="0" height="0" ></svg> | |
<script src="//d3js.org/d3.v4.min.js"></script> | |
<script> | |
var sliderHandleMap = {}; /// a quick fix | |
var sliderFunctionMap = {}; | |
var gCurrentSlider = ""; | |
var g_currentWindow = null; | |
var g_currentWindowLabel = ""; | |
var g_calRange = { | |
"IntervalStart" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalEnd", | |
"exclOp" : function (a,b) { return( a <= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
}, | |
"IntervalEnd" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalStart", | |
"exclOp" : function (a,b) { return( a >= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
} | |
}; | |
var g_numOfMonth = { | |
"January" : 0, | |
"February" : 1, | |
"March" : 2, | |
"April" : 3, | |
"May" : 4, | |
"June" : 5, | |
"July" : 6, | |
"August" : 7, | |
"September" : 8, | |
"October" : 9, | |
"November" : 10, | |
"December" : 11 | |
}; | |
function slide(h,x,handle) { | |
handle.attr("cx", x(h)); | |
} | |
g_currentSelectedCalendar = "CalStart"; | |
function updateTimeIntervalTextDisplay() { | |
var dateStartText = d3.select("#start-date-text"); | |
var dateEndText = d3.select("#end-date-text"); | |
if ( g_calRange["IntervalStart"].time ) { | |
dateStartText.text(g_calRange["IntervalStart"].time.toString()); | |
} else { | |
var dn = new Date(); | |
dateStartText.text(dn.toString()); | |
} | |
if ( g_calRange["IntervalEnd"].time ) { | |
dateEndText.text(g_calRange["IntervalEnd"].time.toString()); | |
} else { | |
var dn = new Date(); | |
dateEndText.text(dn.toString()); | |
} | |
} | |
function update_dateTime(tFacet,txt,whichCal) { | |
var cal = g_currentSelectedCalendar; | |
if ( whichCal ) { | |
cal = whichCal; | |
} | |
var saveOld = g_calRange[cal][tFacet]; | |
g_calRange[cal][tFacet] = txt; | |
var time = new Date( 1*(g_calRange[cal].year), g_numOfMonth[g_calRange[cal].month], g_calRange[cal].day, | |
g_calRange[cal].CalHours, g_calRange[cal].CalMinutes, g_calRange[cal].CalSeconds ); | |
var excl = g_calRange[cal].exclude; | |
if ( g_calRange[excl].time == null ) { | |
g_calRange[cal].time = time; | |
updateTimeIntervalTextDisplay(); | |
return(true); | |
} | |
if ( g_calRange[cal].exclOp(time,g_calRange[excl].time) ) { | |
g_calRange[cal].time = time; | |
updateTimeIntervalTextDisplay(); | |
return(true); | |
} | |
g_calRange[cal][tFacet] = saveOld; | |
return(false); | |
} | |
function rememberTransformation(groupTranslation,widget,whichCal) { | |
var cal = g_currentSelectedCalendar; | |
if ( whichCal ) { | |
cal = whichCal; | |
} | |
g_calRange[cal]["widgets"]["clocksWidget"]["transform"] = groupTranslation; | |
g_calRange[cal]["widgets"]["clocksWidget"]["transformed"] = widget; | |
} | |
function recallTransformation(calCtxt) { | |
var transWidget = calCtxt["widgets"]["clocksWidget"]["transformed"]; | |
if ( transWidget ) { | |
transWidget.attr("transform",calCtxt["widgets"]["clocksWidget"]["transform"]); | |
} | |
} | |
function setCalDates(calContainer) { | |
//------------------------------------------- | |
var yr = calContainer.select("#tspan-year").text(); | |
var mo = calContainer.select("#tspan-month").text(); | |
var moTime = new Date(mo + " 1, " + yr); | |
var curMo = moTime.getMonth(); | |
while ( moTime.getDay() > 0 ) { | |
moTime.setDate(moTime.getDate()-1); | |
} | |
for ( var i = 0; i < 6; i++ ) { | |
for ( var j = 0; j < 7; j++ ) { | |
var tt = calContainer.select("#g_calBox_" + i + "_" + j).selectAll("tspan"); | |
tt.text("" + moTime.getDate()); | |
if ( curMo != moTime.getMonth() ) { | |
calContainer.select("#g_calBox_" + i + "_" + j).selectAll("rect") | |
.style("fill",function() { | |
var rct = d3.select(this); | |
this["preserve-color"] = rct.style("fill"); | |
return("gray"); | |
}) | |
.style("fill-opacity","0.5"); | |
} else { | |
calContainer.select("#g_calBox_" + i + "_" + j).selectAll("rect") | |
.style("fill",function() { | |
var rct = d3.select(this); | |
return( this["preserve-color"] ? this["preserve-color"] : rct.style("fill") ); | |
}) | |
.style("fill-opacity","1"); | |
} | |
moTime.setDate(moTime.getDate()+1); | |
} | |
} | |
} | |
function toolMonth(monthList) { | |
monthList.style("visibility","hidden"); | |
var mos = monthList.selectAll("g") | |
.on("mouseenter", function(){ | |
var color = d3.select(this).select("rect").style("fill"); | |
this["preserve_color"] = color; | |
d3.select(this).select("rect").style("fill","green"); | |
}) | |
.on("mouseleave", function(){ | |
d3.select(this).select("rect").style("fill",this["preserve_color"]); | |
}) | |
.on("click",function() { | |
var month_sel = d3.select(this).attr("id"); | |
var calconP = d3.select(this.parentNode.parentNode); | |
var calcon = calconP.select("#calendar_widget"); | |
var mo = calcon.select("#tspan-month").text(month_sel); | |
update_dateTime("month", month_sel ); | |
setCalDates(calcon); | |
}); | |
} | |
function addSlider(container,maxDomain,maxRange,sliderID) { | |
var whichCal = container.attr("id"); | |
var margin = {right: 50, left: 550}; | |
var width = maxRange - margin.left - margin.right; | |
var height = +container.attr("height"); | |
var x = d3.scaleLinear() | |
.domain([0, maxDomain]) | |
.range([0, maxRange]) | |
.clamp(true); | |
var slider = container.append("g") | |
.attr("id",sliderID) | |
.attr("class", "slider") | |
.attr("visibility","hidden") | |
.attr("transform", "translate(" + margin.left + "," + height / 2 + ")"); | |
slider.append("text").attr("x",x.range()[0]).attr("y",-10).text(sliderID); | |
slider.append("line") | |
.attr("class", "track") | |
.attr("x1", x.range()[0]) | |
.attr("x2", x.range()[1]) | |
.select( function() { return this.parentNode.appendChild(this.cloneNode(true)); } ) | |
.attr("class", "track-inset") | |
.select( function() { return this.parentNode.appendChild(this.cloneNode(true)); } ) | |
.attr("class", "track-overlay") | |
.call(d3.drag() | |
.on("start.interrupt", function() { slider.interrupt(); }) | |
.on("start drag", function () { | |
sliderFunctionMap[gCurrentSlider](); | |
} | |
)); | |
sliderFunctionMap[whichCal + sliderID] = function() { | |
var h = x.invert(d3.event.x-50); | |
if ( update_dateTime( sliderID, h, whichCal ) ) { | |
slide( h , x, sliderHandleMap[whichCal + sliderID] ); | |
} | |
}; | |
slider.insert("g", ".track-overlay") | |
.attr("class", "ticks") | |
.attr("transform", "translate(0," + 18 + ")") | |
.selectAll("text") | |
.data(x.ticks(10)) | |
.enter().append("text") | |
.attr("x", x) | |
.attr("text-anchor", "middle") | |
.text(function(d) { return d + "°"; }); | |
var handle = slider.insert("circle", ".track-overlay") | |
.attr("id","handle_" + sliderID) | |
.attr("class", "handle") | |
.attr("r", 9); | |
sliderHandleMap[whichCal + sliderID] = handle; | |
return(slider); | |
} | |
function hourSelection(hrsClock,svgCalBK) { | |
var vizState = svgCalBK.select("#CalHours").style("visibility"); | |
hrsClock.raise(); | |
hideAllSliders(svgCalBK); | |
if ( vizState == "hidden" ) { | |
var whichCal = svgCalBK.attr("id"); | |
gCurrentSlider = whichCal + "CalHours"; | |
svgCalBK.select("#CalHours").style("visibility","visible"); | |
} | |
} | |
function minuteSelection(minsClock,svgCalBK) { | |
var vizState = svgCalBK.select("#CalMinutes").style("visibility"); | |
minsClock.raise(); | |
hideAllSliders(svgCalBK); | |
if ( vizState == "hidden" ) { | |
var whichCal = svgCalBK.attr("id"); | |
gCurrentSlider = whichCal + "CalMinutes"; | |
svgCalBK.select("#CalMinutes").style("visibility","visible"); | |
} | |
} | |
function secondSelection(secsClock,svgCalBK) { | |
var vizState = svgCalBK.select("#CalSeconds").style("visibility"); | |
secsClock.raise(); | |
hideAllSliders(svgCalBK); | |
if ( vizState == "hidden" ) { | |
var whichCal = svgCalBK.attr("id"); | |
gCurrentSlider = whichCal + "CalSeconds"; | |
svgCalBK.select("#CalSeconds").style("visibility","visible"); | |
} | |
} | |
function hideAllSliders(svgCalBK) { | |
svgCalBK.select("#CalHours").style("visibility","hidden"); | |
svgCalBK.select("#CalMinutes").style("visibility","hidden"); | |
svgCalBK.select("#CalSeconds").style("visibility","hidden"); | |
} | |
function toolCalendar(svgCalBK,exclusionId,calLabel) { | |
var calContainer = svgCalBK.selectAll("g"); | |
calContainer.attr("exclusion",exclusionId); | |
calContainer.on("click", ( function(svgCalBKB,exclID) { return(function() { | |
var calContainer = d3.select(this.parentNode); | |
var exclusion = d3.select(this.parentNode.parentNode).select("#" + exclID); | |
var vbox = calContainer.attr("viewBox"); | |
if ( vbox != "0 0 500 490" ) { | |
calContainer.attr("openstate","closed"); | |
calContainer.lower(); | |
var width = this.parentNode["saveW"]; | |
var height = this.parentNode["saveH"]; | |
calContainer | |
.attr("width", width) | |
.attr("height",height) | |
.attr("viewBox","0 0 500 490"); | |
//var ccg = calContainer.select("#cal-clock-group"); | |
//ccg.attr("transform", this.parentNode["saveCalClockOrigin"] ); | |
for ( var i = 0; i < 6; i++ ) { | |
for ( var j = 0; j < 7; j++ ) { | |
calContainer.select("#g_calBox_" + i + "_" + j).selectAll("rect") | |
.on("mouseenter",null) | |
.on("mouseenter",null) | |
.on("click",null); | |
} | |
} | |
hideAllSliders(svgCalBKB); | |
} else { | |
if ( !exclusion.empty() ) { | |
var open = exclusion.attr("openstate"); | |
if ( open === "open" ) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent( | |
"click", /* type */ | |
true, /* canBubble */ | |
true, /* cancelable */ | |
window, /* view */ | |
0, /* detail */ | |
0, /* screenX */ | |
0, /* screenY */ | |
0, /* clientX */ | |
0, /* clientY */ | |
false, /* ctrlKey */ | |
false, /* altKey */ | |
false, /* shiftKey */ | |
false, /* metaKey */ | |
0, /* button */ | |
null); /* relatedTarget */ | |
(exclusion.select("#calendar_widget").node()).dispatchEvent(evt); | |
} | |
} | |
calContainer.attr("openstate","open"); | |
calContainer.raise(); | |
this.parentNode["saveW"] = calContainer.attr("width"); | |
this.parentNode["saveH"] = calContainer.attr("height"); | |
var width = this.parentNode["saveW"]; | |
var height = this.parentNode["saveH"]; | |
var w = window, | |
d = document, | |
e = d.documentElement, | |
g = d.getElementsByTagName('body')[0], | |
wx = w.innerWidth || e.clientWidth || g.clientWidth, | |
wy = w.innerHeight|| e.clientHeight|| g.clientHeight; | |
var xratioWin = window.screen.width/wx; | |
var yratioWin = window.screen.height/wy; | |
var xW = Math.round(300*xratioWin); | |
var yW = Math.round(490*yratioWin); | |
calContainer | |
.attr("width", width*4) | |
.attr("height",height*8) | |
.attr("viewBox","0 0 " + xW + " " + yW); | |
g_currentSelectedCalendar = svgCalBKB.attr("id"); | |
var ccg = calContainer.select("#cal-clock-group"); | |
ccg.raise(); | |
//this.parentNode["saveCalClockOrigin"] = ccg.attr("transform"); | |
for ( var i = 0; i < 6; i++ ) { | |
for ( var j = 0; j < 7; j++ ) { | |
calContainer.selectAll( "#g_calBox_" + i + "_" + j ).selectAll("rect") | |
.on("mouseenter",function() { | |
var boxC = d3.select(this); | |
if ( boxC.style("fill") == "rgb(255, 255, 255)" ) { | |
boxC.style("fill","green"); | |
} | |
}) | |
.on("mouseleave",function() { | |
var boxC = d3.select(this); | |
if ( boxC.style("fill") == "rgb(0, 128, 0)" ) { | |
boxC.style("fill","#ffffff"); | |
} | |
}) | |
.on("click",(function(calCtr) { return( | |
function() { | |
d3.event.stopPropagation(); | |
var boxC = d3.select(this); | |
var bX = 1*boxC.attr("x"); | |
var bY = 1*boxC.attr("y"); | |
var boxGroup = d3.select(this.parentNode); | |
var dayTxt = boxGroup.select("tspan").text(); | |
if ( !update_dateTime("day",dayTxt) ) return; | |
var ccg = calCtr.select("#cal-clock-group"); | |
var groupRow = d3.select(this.parentNode.parentNode); | |
var t = groupRow.attr("transform"); | |
var y = 0; | |
if ( t != null ) { | |
var numberPattern = /[+-]?\d+(\.\d+)?/g; | |
var els = t.match( numberPattern ); | |
y = 1*els[1]; | |
} | |
var h = 1*boxC.attr("height"); | |
var clockGroupTranslation = "translate(" + [ bX - 500, y + h/3 ] + ")"; | |
rememberTransformation(clockGroupTranslation,ccg); | |
ccg.attr("transform",clockGroupTranslation); | |
ccg.raise(); | |
} | |
);})(calContainer) ); | |
} | |
} | |
} | |
}); })(svgCalBK,exclusionId) ); | |
var calclocks = calContainer.select("#cal-clock-group-background"); | |
calclocks.on("click",function() { d3.event.stopPropagation(); } ); | |
var calclockHour = calContainer.selectAll("#cal-clock-H"); | |
var calclockMin = calContainer.selectAll("#cal-clock-M"); | |
var calclockSecs = calContainer.selectAll("#cal-clock-S"); | |
calclockHour.on("click", (function(svgCalBKB){ return( | |
function() { | |
d3.event.stopPropagation(); | |
hourSelection(d3.select(this),svgCalBKB); | |
} ); })(svgCalBK) ); | |
calclockMin.on("click", (function(svgCalBKB){ return( | |
function() { | |
d3.event.stopPropagation(); | |
minuteSelection(d3.select(this),svgCalBKB); | |
} ); })(svgCalBK) ); | |
calclockSecs.on("click", (function(svgCalBKB){ return( | |
function() { | |
d3.event.stopPropagation(); | |
secondSelection(d3.select(this),svgCalBKB); | |
} ); })(svgCalBK) ); | |
setCalDates(calContainer); | |
var month_button = calContainer.select("#month_button").on("click", (function(svgCalBKB) { | |
return(function() { | |
d3.event.stopPropagation(); | |
var mlist = svgCalBKB.select("#cal-month_list"); | |
mlist.raise(); | |
var vis = mlist.style("visibility") == "hidden" ? "visible" : "hidden"; | |
mlist.style("visibility",vis); | |
}); | |
})(svgCalBK) ); | |
// calLabel | |
var label = calContainer.select("#interval-boundary").select("tspan").text(calLabel); | |
} | |
// ppoakf0k | |
var keydown = function() { | |
if (!focused) return; | |
var text = focused.text; | |
var code = d3.event.keyCode; | |
if (code == 8) { // Backspace | |
d3.event.preventDefault(); | |
text = text.substring(0,text.length-1); | |
}; | |
if (code == 13) { // Enter | |
focused.stroke = d3.rgb(240,240,240); | |
focused.callback(); | |
}; | |
//console.log("keydown: code: "+ code + ", text: "+text); | |
focused.text = text; | |
} | |
var keypress = function() { | |
if (!focused) return; | |
var text = focused.text; | |
var code = d3.event.keyCode; | |
text = text+String.fromCharCode(code); | |
//console.log("keypress: code: "+ code + ", text: "+text); | |
focused.text = text; | |
} | |
var focused = null; | |
d3.select("body") | |
.on("keydown",keydown) | |
.on("keypress",keypress) | |
.on("click", function() { | |
if (focused) { | |
focused.stroke = d3.rgb(240,240,240); | |
focused = null; | |
} | |
}); | |
function Textbox(textgroup) { | |
var text = "", | |
fontsize = 12; | |
var stroke = d3.rgb(240,240,240), | |
fill = d3.rgb(255,255,255); | |
var rct = textgroup.select("#backing-rect"); | |
var width = rct.attr("width"); | |
var height = rct.attr("height"); | |
var txt = textgroup.select("text"); | |
var x = txt.attr("x"); | |
var y = txt.attr("y"); | |
var cover = textgroup.append("rect") // Transparent cover to hide cursor when mousing over text | |
.attr("width", width) | |
.attr("height", height) | |
.attr("x",x) | |
.attr("y",y) | |
.style("opacity", 0); | |
var txt_width = txt.node().getComputedTextLength(); | |
var callback = function() { | |
console.log("Text: "+txt.text()); | |
} | |
var aligntext = function() { | |
txt.attr("x",x+10); // + .5*(width-txt_width) | |
txt.attr("y",y); // + .5*(height+fontsize)-2 | |
}; | |
function textbox() { | |
} | |
Object.defineProperty(textbox,"text",{ | |
get: function() {return text;}, | |
set: function(_) { | |
text = _; | |
txt.text(_); | |
txt_width = txt.node().getComputedTextLength(); | |
aligntext(); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"x",{ | |
get: function() {return x;}, | |
set: function(_) { | |
x = _; | |
textgroup.attr("transform", "translate(" + x + "," + y + ")"); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"y",{ | |
get: function() {return y;}, | |
set: function(_) { | |
y = _; | |
textgroup.attr("transform", "translate(" + x + "," + y + ")"); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"width",{ | |
get: function() {return width;}, | |
set: function(_) { | |
width = _; | |
rct.attr("width",_); | |
cover.attr("width",_); | |
aligntext(); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"height",{ | |
get: function() {return height;}, | |
set: function(_) { | |
height = _; | |
rct.attr("height",_); | |
cover.attr("height",_); | |
aligntext(); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"position",{ | |
get: function() {return [x, y, width, height];}, | |
set: function(_) { | |
textbox.x = _[0]; | |
textbox.y = _[1]; | |
textbox.width = _[2]; | |
textbox.height = _[3]; | |
}, | |
enumerable: true, | |
cofigurable: true | |
}) | |
Object.defineProperty(textbox,"stroke",{ | |
get: function() {return stroke;}, | |
set: function(_) { | |
stroke = _; | |
rct.style("stroke",stroke); | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"cover",{ | |
get: function() {return cover;}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
Object.defineProperty(textbox,"callback",{ | |
get: function() {return callback;}, | |
set: function(_) { | |
callback = _; | |
}, | |
enumerable: true, | |
cofigurable: true | |
}); | |
cover.on("click", function() { | |
focused = textbox; | |
rct.style("stroke","#347bbe"); | |
d3.event.stopPropagation(); | |
}); | |
return textbox; | |
} | |
function toolApplication(appfile,appArea) { | |
// appfile for later applicatio differentiation and js loading | |
appArea.selectAll(".svg-checkbox").on("click",function() { | |
d3.event.stopPropagation(); | |
d3.select(this.parentNode).select("path").style("visibility","visible"); | |
}); | |
appArea.selectAll(".svg-checkbox-sel").on("click",function() { | |
d3.event.stopPropagation(); | |
var stl = d3.select(this).style("visibility"); | |
if ( stl == "hidden" ) { | |
d3.select(this).style("visibility","visible"); | |
} else { | |
d3.select(this).style("visibility","hidden"); | |
} | |
}); | |
// appfile for later applicatio differentiation and js loading | |
appArea.selectAll(".svg-radiobutton-off").on("click",function() { | |
d3.event.stopPropagation(); // parent node is a group | |
d3.select(this.parentNode.parentNode.parentNode).selectAll(".svg-radiobutton-on").style("visibility","hidden"); | |
d3.select(this.parentNode).select(".svg-radiobutton-on").style("visibility","visible"); | |
}); | |
appArea.selectAll(".svg-radiobutton-on").on("click",function() { | |
d3.event.stopPropagation(); | |
var stl = d3.select(this).style("visibility"); | |
if ( stl == "hidden" ) { | |
d3.select(this.parentNode.parentNode.parentNode).selectAll(".svg-radiobutton-on").style("visibility","hidden"); | |
d3.select(this).style("visibility","visible"); | |
} else { | |
d3.select(this).style("visibility","hidden"); | |
} | |
}); | |
var t = new Textbox(appArea.select("#text-edit-group-1")); | |
var wDat = findCurrentWindowData(); | |
wDat.contextualized = true; | |
} | |
var daysOfWeek = null; | |
function nestApplication( appArea, appfile, x, y ) { | |
d3.request((appfile), | |
function(resp) { | |
appArea.html(resp.response); | |
toolApplication(appfile,appArea); | |
}); | |
} | |
function nestCalendar(selParent,calId,x,y,width,height,exclusivePair,calLabel) { | |
var w = window, | |
d = document, | |
e = d.documentElement, | |
g = d.getElementsByTagName('body')[0], | |
wx = w.innerWidth || e.clientWidth || g.clientWidth, | |
wy = w.innerHeight|| e.clientHeight|| g.clientHeight; | |
selParent.append("svg") | |
.attr("id",calId) | |
.attr("x", x ) | |
.attr("y", y ) | |
.attr("width", Math.min(width,wx)) | |
.attr("height",Math.min(height,wy)) | |
.attr("viewBox","0 0 500 490") | |
.attr("preserveAspectRatio","xMinYMin meet"); | |
var svgCal = selParent.select("svg"); | |
d3.request("xcalendar-group.svg", | |
function(resp) { | |
var svgCalBK = selParent.select("#" + calId); | |
svgCalBK.html(resp.response); | |
toolCalendar(svgCalBK,exclusivePair,calLabel); | |
d3.request("month-list.svg", | |
(function(svgCalB) { return( | |
function(resp) { | |
var monthList = svgCalB.append("g").attr("id","cal-month_list").html(resp.response); | |
var hoursPerDay = addSlider(svgCalB,24,300,"CalHours"); | |
var minutePerHour = addSlider(svgCalB,60,300,"CalMinutes"); | |
var secondsPerMinut = addSlider(svgCalB,60,300,"CalSeconds"); | |
toolMonth(monthList); | |
}); })(svgCalBK) ); | |
}); | |
} | |
/* -- // d3 example by Richard Leddy (c) 2016 */ | |
function updateRemove(pSvg,d) { | |
var ms = pSvg.selectAll("#win-" + d.iam); | |
ms.remove(); | |
} | |
function update_control_context(ctxtCtrl,d) { | |
if ( d.iam == "context" ) return; | |
ctxtCtrl.text(d.iam); | |
recallTransformation(d.context["IntervalStart"]); | |
recallTransformation(d.context["IntervalEnd"]); | |
g_calRange = d.context; | |
updateTimeIntervalTextDisplay(); | |
if ( g_currentWindow ) { | |
g_currentWindow.select("#step-action-message").text("click the green circle"); | |
} | |
} | |
var topSvg = d3.select("#mainsvg"); | |
var w = window, | |
d = document, | |
e = d.documentElement, | |
g = d.getElementsByTagName('body')[0], | |
wx = w.innerWidth || e.clientWidth || g.clientWidth, | |
wy = w.innerHeight|| e.clientHeight|| g.clientHeight; | |
topSvg.attr("width",window.screen.width); | |
topSvg.attr("height",window.screen.height); | |
var winCount = 0; | |
var width = wx, | |
height = wy, | |
radius = 300; | |
var rectsAll = d3.range(6).map(function() { | |
return { | |
iam: winCount++, | |
x: Math.round(Math.random() * (width/2 - radius * 2) + radius), | |
y: Math.round(Math.random() * (height/2 - radius * 2) + radius), | |
w : radius, | |
h : radius/2, | |
contextualized : false, | |
context: { | |
"IntervalStart" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalEnd", | |
"exclOp" : function (a,b) { return( a <= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
}, | |
"IntervalEnd" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalStart", | |
"exclOp" : function (a,b) { return( a >= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
} | |
} | |
}; | |
}); | |
rectsAll.push({ | |
iam: "context", | |
x: 40, | |
y: 40, | |
w : 2*width/3, | |
h : radius/3, | |
context: { | |
"IntervalStart" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalEnd", | |
"exclOp" : function (a,b) { return( a <= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
}, | |
"IntervalEnd" : { | |
"year" : "2016", | |
"month" : "August", | |
"day" : 1, | |
"CalHours" : 0, | |
"CalMinutes" : 0, | |
"CalSeconds" : 0, | |
"exclude" : "IntervalStart", | |
"exclOp" : function (a,b) { return( a >= b ); }, | |
"time" : null, | |
"widgets" : { | |
"clocksWidget" : { | |
"transform" : null, | |
"transformed" : null | |
} | |
} | |
} | |
} | |
}); | |
var color = d3.scaleOrdinal() | |
.range(d3.schemeCategory20); | |
function findCurrentWindowData() { | |
var j = rectsAll.findIndex(function(obj){ var res = (obj.iam === g_currentWindowLabel); return res; }); | |
return(rectsAll[j]); | |
} | |
function addWindows(pSvg,defRegions) { | |
var rectangle = pSvg.selectAll("g.windowBox") | |
.data(defRegions, function(d) { return(d.iam); } ) | |
.enter().append("g") | |
.attr("id", function(d){ return("win-" + d.iam); } ) | |
.attr("class","windowBox") | |
.call(d3.drag() | |
.on("start", dragstarted) | |
.on("drag", dragged) | |
.on("end", dragended)); | |
rectangle.attr("deltaX",function(d) { return(0); }) | |
.attr("deltaY",function(d) { return(0); }); | |
// This is the containing box window | |
rectangle.append("rect") | |
.attr("x", function(d) { return d.x; }) | |
.attr("y", function(d) { return d.y; }) | |
.attr("height", function(d) { return d.h; }) | |
.attr("width", function(d) { return d.w; }) | |
.attr("cursor", "move") | |
.style("fill", function(d, i) { return color(i); }); | |
/* | |
rectangle.append("circle") | |
.attr("cx", function(d) { return d.x + d.w; }) | |
.attr("cy", function(d) { return d.y + d.h; }) | |
.attr("r", function(d) { return d.h; }) | |
//.attr("width", function(d) { return d.w; }) | |
.attr("cursor", "move") | |
.style("fill", function(d, i) { return color(i); }); | |
*/ | |
var noDrag = d3.drag() | |
.on('start', function(d){ | |
g_currentWindowLabel = d.iam; | |
g_currentWindow = d.iam != "context" ? d3.select(this.parentNode) : null; | |
if ( g_currentWindow == null ) return; | |
d3.select(this.parentNode).raise().classed("active", true); | |
var ctxtCtrl = d3.select("#data-context-control-text"); | |
update_control_context(ctxtCtrl,d); | |
}) | |
.on('drag', function(d,i){ | |
}) | |
.on("end", function(d,i){ | |
d3.select(this.parentNode).classed("active", false); | |
}); | |
// This is the interior box window | |
rectangle.append("rect") | |
.attr("x", function(d) { return d.x+1; }) | |
.attr("y", function(d) { return d.y+20; }) | |
.attr("height", function(d) { return d.h-22; }) | |
.attr("width", function(d) { return d.w-2; }) | |
.style("fill", function(d, i) { return "#FAFACC"; }) | |
.call(noDrag); | |
var dragBox = d3.drag() | |
.on('start', function(d){ | |
g_currentWindowLabel = d.iam; | |
g_currentWindow = d.iam != "context" ? d3.select(this.parentNode) : null; | |
d3.event.sourceEvent.stopPropagation(); | |
var ctxtCtrl = d3.select("#data-context-control-text"); | |
update_control_context(ctxtCtrl,d); | |
}) | |
.on('drag', function(d,i){ | |
var resizeBox = d3.select(this); | |
var mx = +resizeBox.attr("x"); | |
var my = +resizeBox.attr("y"); | |
var topLimit = d.y + 20; | |
var leftLimit = d.x + 20; | |
mx += d3.event.dx; | |
if ( d.iam != "context" ) { | |
my += d3.event.dy; | |
} | |
if ( (mx > leftLimit) && (my > topLimit) ) { | |
resizeBox.attr('x', mx).attr('y', my); | |
var height = my - d.y; | |
var width = mx - d.x; | |
d3.select(this.previousElementSibling) | |
.attr("x", mx); | |
d3.select(this.previousElementSibling.previousElementSibling) | |
.attr("width", width + 10 - 2) | |
.attr("height", height + 10 - 22); | |
d3.select(this.previousElementSibling.previousElementSibling.previousElementSibling) | |
.attr("width", width + 10) | |
.attr("height", height + 10); | |
var subView = d3.select(this.parentNode).select("svg"); | |
if ( !subView.empty()) { | |
var resF = subView.attr("custom-resize"); | |
if ( resF && d.resize ) { | |
d.resize(subView,d,width,height); | |
} | |
} | |
} | |
}); | |
rectangle.append("rect") | |
.attr("x", function(d) { return d.x + d.w - 10; }) | |
.attr("y", function(d) { return d.y; }) | |
.attr("height", 10) | |
.attr("width", 10) | |
.attr("fill", "navy" ) | |
.attr("cursor","pointer") | |
.on("click", function(d,i) { | |
if ( d.iam == "context" ) return; | |
var j = rectsAll.findIndex(function(obj){ var res = (obj.iam === d.iam); return res; }); | |
rectsAll.splice(j,1); | |
updateRemove(pSvg,d); | |
var rect = d3.select(this); | |
var cc = rect.attr("fill"); | |
cc = (cc == "navy" )? "green" : "navy"; | |
rect.attr("fill",cc); | |
}); | |
rectangle.append("rect") | |
.attr("x", function(d) { return d.x + d.w - 10; }) | |
.attr("y", function(d) { return d.y + d.h - 10; }) | |
.attr("height", 10) | |
.attr("width", 10) | |
.style("fill", function(d, i) { return "#993300"; }) | |
.attr("cursor", "nw-resize") | |
.call(dragBox); | |
rectangle.append("text") | |
.attr("x", function(d) { return d.x + 20; }) | |
.attr("y", function(d) { return d.y + 60; }) | |
.attr("id","step-action-message") | |
.text(function(d) { return( d.iam != "context" ? "Click me to make this window active" : "parameter window" ); } ) | |
.call(dragBox); | |
} | |
function dragstarted(d) { | |
g_currentWindowLabel = d.iam; | |
g_currentWindow = d.iam != "context" ? d3.select(this) : null; | |
var dltX = 1*(d3.select(this).attr("deltaX")); | |
var dltY = 1*(d3.select(this).attr("deltaY")); | |
d3.select(this).attr("deltaX",d3.event.x - dltX); | |
d3.select(this).attr("deltaY",d3.event.y - dltY); | |
d3.select(this).raise().classed("active", true); | |
var ctxtCtrl = d3.select("#data-context-control-text"); | |
update_control_context(ctxtCtrl,d); | |
} | |
function dragged(d) { | |
var dltX = 1*(d3.select(this).attr("deltaX")); | |
var dltY = 1*(d3.select(this).attr("deltaY")); | |
d3.select(this).attr("transform", function(d,i){ | |
return "translate(" + [ d3.event.x - dltX, d3.event.y - dltY] + ")" | |
}); | |
} | |
function dragended(d, i) { | |
var dltX = 1*(d3.select(this).attr("deltaX")); | |
var dltY = 1*(d3.select(this).attr("deltaY")); | |
d3.select(this).attr("deltaX",d3.event.x - dltX); | |
d3.select(this).attr("deltaY",d3.event.y - dltY); | |
d3.select(this).classed("active", false); | |
} | |
function renderCell(d) { | |
return d == null ? null : "M" + d.join("L") + "Z"; | |
} | |
topSvg.append("rect") | |
.attr("x",5) | |
.attr("y",5) | |
.attr("height",20) | |
.attr("width",20).attr("fill","orange") | |
.style("cursor","pointer") | |
.on("click", function() { | |
var rect = d3.select(this); | |
var cc = rect.attr("fill"); | |
cc = cc == "orange" ? "blue" : "orange"; | |
rect.attr("fill",cc); | |
var newDatum = { | |
iam: winCount++, | |
x: Math.round(Math.random() * (width/2 - radius * 2) + radius), | |
y: Math.round(Math.random() * (height/2 - radius * 2) + radius), | |
w : radius, | |
h : radius/2 | |
}; | |
console.log(newDatum); | |
rectsAll.push(newDatum); | |
addWindows(topSvg,rectsAll); | |
}); | |
topSvg.append("circle") | |
.attr("cx",40) | |
.attr("cy",15) | |
.attr("r",10).attr("fill","darkgreen") | |
.style("cursor","pointer") | |
.on("click", function() { | |
if ( g_currentWindow ) { | |
var wDat = findCurrentWindowData(); | |
if ( wDat.contextualized ) return; | |
var ww = g_currentWindow.select("rect").attr("width"); | |
var hh = g_currentWindow.select("rect").attr("height"); | |
g_currentWindow.append("svg") | |
.attr("id","applicatoin" + g_currentWindow.attr("id")) | |
.attr("x", function(d){return d.x}) | |
.attr("y", function(d){return (d.y + 20) }) | |
.attr("width", ww-10 ) | |
.attr("height", hh-30 ) | |
.attr("preserveAspectRatio","xMinYMin meet") | |
.attr("custom-resize",function(d) { // clip the content of this window in a particular way. | |
d.resize = function(subsvg,data,w,h) { | |
subsvg.attr("height",h); | |
subsvg.attr("width",w); | |
} | |
return("true"); | |
}); | |
nestApplication( g_currentWindow.select("svg"), "form-icecream.svg", 10, 22 ); | |
} | |
/* | |
var rect = d3.select(this); | |
var cc = rect.attr("fill"); | |
cc = cc == "darkgreen" ? "purple" : "darkgreen"; | |
rect.attr("fill",cc); | |
var newDatum = { | |
iam: winCount++, | |
x: Math.round(Math.random() * (width/2 - radius * 2) + radius), | |
y: Math.round(Math.random() * (height/2 - radius * 2) + radius), | |
w : radius, | |
h : radius/2 | |
}; | |
console.log(newDatum); | |
rectsAll.push(newDatum); | |
addWindows(topSvg,rectsAll); | |
*/ | |
}); | |
addWindows(topSvg,rectsAll); | |
var context_window = topSvg.select("#win-context") | |
.append("svg") | |
.attr("id","data-context-control") | |
.attr("x", function(d){return d.x}) | |
.attr("y", function(d){return d.y}) | |
.attr("width", function(d){return width;}) | |
.attr("height", function(d){return height;}) | |
.attr("custom-resize",function(d) { // clip the content of this window in a particular way. | |
d.resize = function(subsvg,data,w,h) { | |
subsvg.attr("width",w); | |
} | |
return("true"); | |
}) | |
.append("text") | |
.attr("id","data-context-control-text") | |
.attr("stroke","black") | |
.attr("x", function(d){return 10}) | |
.attr("y", function(d){return 15}) | |
.text(function(d){ return "context"; }); | |
topSvg.select("#win-context").select("svg").append("text") | |
.attr("id","start-date-text") | |
.attr("stroke","rgb(50,230,0)") | |
.attr("fill","rgb(220,230,0)") | |
.attr("x", function(d){return 150}) | |
.attr("y", function(d){return 15}) | |
.text(function(d){ return "present"; }); | |
topSvg.select("#win-context").select("svg").append("text") | |
.attr("id","end-date-text") | |
.attr("stroke","rgb(50,230,0)") | |
.attr("fill","rgb(200,230,0)") | |
.attr("x", function(d){return 550}) | |
.attr("y", function(d){return 15}) | |
.text(function(d){ return "present"; }); | |
updateTimeIntervalTextDisplay(); | |
nestCalendar( topSvg.select("#win-context").select("svg"), "IntervalStart", 10, 22, 45*7, 72, "IntervalEnd", "Start"); | |
nestCalendar( topSvg.select("#win-context").select("svg"), "IntervalEnd", 90, 22, 45*7, 72, "IntervalStart", "Stop"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment