Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <head>
	
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<title>SVG Animation with Snap.svg</title>
   
</head>

<body>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="./wrDisplay_01.js"></script>
<script>


$(document).ready(function() {
    console.log("Ready!");
    loadSVGAnimation();
});


</script>
<!-- Note: 
        Using CSS to change width and height works with Chrome but not with Firfox 
        For Details:  https://stackoverflow.com/questions/36363285/setting-svg-element-width-height-attributes-using-css-in-firefox
 "  -->
 <svg id="svgCanvas" width="535" height="280" viewBox="0 0 535 280"  preserveAspectRatio="xMinYMin meet" xmlns="http://www.w3.org/2000/svg">
  
    <defs>
    <linearGradient id="button_surface1" gradientUnits="objectBoundingBox"
      x1="1" x2="1" y1="0" y2="1">
      <stop stop-color="#808080" offset="0"/>
      <stop stop-color="#DDDDDD" offset="0.67"/>
    </linearGradient>
    
   <linearGradient id="button_surface2" gradientUnits="objectBoundingBox"
      x1="1" x2="1" y1="0" y2="1">
      <stop stop-color="#00009F" offset="0"/>
      <stop stop-color="#0000FF" offset="0.67"/>
    </linearGradient>
    
    <filter id="virtual_light" filterUnits="objectBoundingBox"
      x="-0.1" y="-0.1" width="1.2" height="1.2">
      <feGaussianBlur in="SourceAlpha" stdDeviation="2" result="alpha_blur"/>

      <!-- virtual shadow effect -->
      <feOffset in="alpha_blur" dx="4" dy="4" result="offset_alpha_blur"/>

      <!-- vitual lighting effect -->
      <feSpecularLighting in="alpha_blur" surfaceScale="5" specularConstant="1"
        specularExponent="20" lighting-color="#FFFFFF" result="spec_light">
        <fePointLight x="-5000" y="-10000" z="10000"/>
      </feSpecularLighting>
      <feComposite in="spec_light" in2="SourceAlpha" operator="in"
        result="spec_light"/>
      <feComposite in="SourceGraphic" in2="spec_light"
        operator="out" result="spec_light_fill"/>

      <!-- combine effects -->
      <feMerge>
        <feMergeNode in="offset_alpha_blur"/>
        <feMergeNode in="spec_light_fill"/>
      </feMerge>
    </filter>
  </defs>

  <!-- button content -->
   <rect id="svgRect0" x="5" y="5" rx="15" ry="15" width="520" height="260" fill="url(#button_surface1)" stroke="#360000" filter="url(#virtual_light)"  />
   	
  <g id="svgGroup1">  
  	 <text id="svgTextHeadlineG1"  x="15" y="30" font-size="20px" font-family="Tahoma" font-weight="500"  fill="black"  >PV Igensdorf [99 kWh] </text>

  	<rect id="svgRect1G1" x="10" y="40" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
  	<rect id="svgRect2G1" x="120" y="40" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
  	<rect id="svgRect3G1" x="230" y="40" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
  	<rect id="svgRect4G1" x="340" y="40" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
 
  	<text id="svgText1HeaderG1" x="20" y="60" font-size="11px" font-family="Tahoma" font-weight="400" fill="white"  >Tages-Produktion:</text>
  	<text id="svgText1G1"       x="60" y="90" font-size="20px" font-family="Tahoma" font-weight="500"  fill="white"  text-anchor="middle"> -- kWh </text>
  
  	<text id="svgText2HeaderG1" x="130" y="60" font-size="11px" font-family="Tahoma" font-weight="400" fill="white">Akuelle Leistung: </text>      
  	<text id="svgText2G1"       x="175" y="90" font-size="20px" font-family="Tahoma" font-weight="500"  fill="white" text-anchor="middle"> -- kWh </text>
  
  	<text id="svgText3HeaderG1" x="245" y="60" font-size="13px" font-family="Tahoma" font-weight="600" fill="white" >[kWh/kWp]</text>      
  	<text id="svgText3G1"       x="280" y="90" font-size="20px" font-family="Tahoma" font-weight="500" fill="white" text-anchor="middle">0.0</text>  
    
  	<text id="svgText4HeaderG1" x="355" y="60" font-size="13px" font-family="Tahoma" font-weight="600"  fill="white">[kW/kWp]</text>      
  	<text id="svgText4G1"       x="395" y="90" font-size="20px" font-family="Tahoma" font-weight="500" fill="white" text-anchor="middle">0.0</text>  

  	<image id="svgTrafficLightImgG1" x="455" y="35" width="70" height="80px" href="images/tlight_green.gif"/>
  </g> 
  <g id="svgGroup2">  
  	<text id="svgTextHeadlineG2"  x="20" y="145" font-size="20px" font-family="Tahoma" font-weight="500"  fill="black"  >PV Sattelmannsburg I [4,7 kWh] </text>  
    <rect id="svgRect1G2" x="15"  y="155" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
    <rect id="svgRect2G2" x="125" y="155" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
    <rect id="svgRect3G2" x="235" y="155" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
    <rect id="svgRect4G2" x="345" y="155" rx="15" ry="15" width="100" height="60"  fill="url(#button_surface2)" stroke="#360000" filter="url(#virtual_light)"/>
   
    <text id="svgText1HeaderG2" x="20" y="175" font-size="11px" font-family="Tahoma" font-weight="400" fill="white"  >Tages-Produktion:</text>
  	<text id="svgText1G2"       x="60" y="205" font-size="20px" font-family="Tahoma" font-weight="500"  fill="white"  text-anchor="middle"> -- kWh </text>
  
  	<text id="svgText2HeaderG2" x="130" y="175" font-size="11px" font-family="Tahoma" font-weight="400" fill="white">Akuelle Leistung: </text>      
  	<text id="svgText2G2"       x="175" y="205" font-size="20px" font-family="Tahoma" font-weight="500"  fill="white" text-anchor="middle"> -- kWh </text>
  
  	<text id="svgText3HeaderG2" x="245" y="175" font-size="13px" font-family="Tahoma" font-weight="600" fill="white" >[kWh/kWp]</text>      
  	<text id="svgText3G2"       x="280" y="205" font-size="20px" font-family="Tahoma" font-weight="500" fill="white" text-anchor="middle">0.0</text>  
    
  	<text id="svgText4HeaderG2" x="355" y="175" font-size="13px" font-family="Tahoma" font-weight="600"  fill="white">[kW/kWp]</text>      
  	<text id="svgText4G2"       x="395" y="205" font-size="20px" font-family="Tahoma" font-weight="500" fill="white" text-anchor="middle">0.0</text> 
    
    <image id="svgTrafficLightImgG2" x="455" y="150" width="70" height="80px" href="images/tlight_green.gif"/>

  </g> 
  
         	 	
</svg>
 
</body>
            
          
!
            
               h1{ text-align:center; }
    a { text-align:center;
    	display: block;  }
	svg {
    	display: block;
    	margin: 0 auto;
    	background-color: "#9e9e9e1a";
	}
	
            
          
!
            
              "use strict";

function loadSVGAnimation() {
	try {
        animateDisplay();
	} catch (e) { 
		console.log("loadSVGAnimation Failed " + e);
		throw e;   
	}
}

function updatePanelMode1(sel, addInfo, val) {
	var htmlSelector = sel;
	var addText = addInfo;
	var svgTextElement = null;
	var actVal = val;
	var panelTxt = "";

	svgTextElement =  Snap.select(htmlSelector);
	panelTxt = actVal + " " + addText;
	svgTextElement.node.innerHTML = panelTxt;
	return svgTextElement;
}

function updatePanelMode2(sel, aPower, mPower ) {
	var htmlSelector = sel;
	var maxPower = mPower;
	var actPower = aPower;
	var svgTextElement = null;
	var n = 0.0;
	var panelTxt = "";

	svgTextElement =  Snap.select(htmlSelector);
	n = (actPower/maxPower).toFixed(2);
	panelTxt = n;
	svgTextElement.node.innerHTML = panelTxt;
	return n;
}

function updateTrafficLight(sel, aPower, tlightImage ) {
    var htmlSelector = sel;
    var actPowerProKW = aPower;
    var tlight ="";
    var svgTrafficLight = Snap.select(sel);
	if (actPowerProKW <= 0.3 ) {
		tlight="tlight_red.gif";
	} else if ( actPowerProKW >= 0.3 && actPowerProKW <= 0.5 ) {
		tlight="tlight_yellow.gif";
	} else {
		tlight="tlight_green.gif";
	}
	var elem =document.getElementById(tlightImage);
	elem.href.baseVal=('http:/pvlocal.de/test/images/' + tlight );
}

function animateDisplay() {
	animateGroup("G1");
	animateGroup("G2");
	setTimeout(animateDisplay, 3000);
}

function  animateGroup(g) {
	var groupID = g;
	var txt1 = "---";
	var txt2 = "---";
	var txt3 = "0.0";
	var txt4 = "0.0";
	var tlight="tlight_yellow.gif";
	var svgTextElement1 = null;
	var svgTextElement2 = null;
	var svgTextElement3 = null;
	var svgTextElement4 = null;
	var svgTrafficLight = null;
	var maxFountSize=22;
	var timing = 1500;
	var actDayPower, actPower, actDayPowerProKW, actPowerProKW;
	actPower = actDayPowerProKW = actPowerProKW = 0.0;
	var htmlSelector1 = "#svgText1" + groupID;
	var htmlSelector2 = "#svgText2" + groupID;
	var htmlSelector3 = "#svgText3" + groupID;
	var htmlSelector4 = "#svgText4" + groupID;
	var htmlSelectTL =   "#svgTrafficLight" + groupID;
	var htmlSelectTLImage =   "svgTrafficLightImg" + groupID;
	var maxPower = 90; // kWP

	actDayPower = Math.floor((Math.random() * 999) + 1);
	svgTextElement1 = updatePanelMode1(htmlSelector1,"kWh", actDayPower);

	actPower = Math.floor((Math.random() * 100) + 1);
	svgTextElement2 = updatePanelMode1(htmlSelector2, "kW", actPower);

	actDayPowerProKW = updatePanelMode2(htmlSelector3, actDayPower, maxPower);
	svgTextElement3 =  Snap.select(htmlSelector3);

	actPowerProKW = updatePanelMode2(htmlSelector4, actPower, maxPower);
	svgTextElement4 =  Snap.select(htmlSelector4);

	updateTrafficLight(htmlSelectTL, actPowerProKW, htmlSelectTLImage);

	Snap.animate( 0, 1, function( value ) {
                    //svgTextElement.transform('s' + value   );                              // Animate by transform
		svgTextElement1.attr({ 'font-size': value * maxFountSize ,  opacity: value });      // Animate by font-size 
		svgTextElement2.attr({ 'font-size': value * maxFountSize,  opacity: value });       // and opacity !
		svgTextElement3.attr({ 'font-size': value * maxFountSize,  opacity: value });
    }, timing, mina.bounce, function() {  } );     
	
}


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console