How to use attrs method in storybook-root

Best JavaScript code snippet using storybook-root

angularjs-nvd3-directives.js

Source:angularjs-nvd3-directives.js Github

copy

Full Screen

1/*! angularjs-nvd3-directives - v0.0.7 - 2014-04-072 * http://cmaurer.github.io/angularjs-nvd3-directives3 * Copyright (c) 2014 Christian Maurer; Licensed Apache License, v2.0 */4( function () {5 'use strict';6 angular.module( 'legendDirectives', [] ).directive( 'simpleSvgLegend', function () {7 return {8 restrict: 'EA',9 scope: {10 id: '@',11 width: '@',12 height: '@',13 margin: '@',14 x: '@',15 y: '@',16 labels: '@',17 styles: '@',18 classes: '@',19 shapes: '@',20 padding: '@',21 columns: '@'22 },23 compile: function () {24 return function link( scope, element, attrs ) {25 var id, width, height, margin, widthTracker = 0,26 heightTracker = 0,27 columns = 1,28 columnTracker = 0,29 padding = 10,30 paddingStr, svgNamespace = 'http://www.w3.org/2000/svg',31 svg, g, labels, styles, classes, shapes, x = 0,32 y = 0;33 margin = scope.$eval( attrs.margin ) || {34 left: 5,35 top: 5,36 bottom: 5,37 right: 538 };39 width = attrs.width === 'undefined' ? element[ 0 ].parentElement.offsetWidth - ( margin.left + margin.right ) : +attrs.width - ( margin.left + margin.right );40 height = attrs.height === 'undefined' ? element[ 0 ].parentElement.offsetHeight - ( margin.top + margin.bottom ) : +attrs.height - ( margin.top + margin.bottom );41 if ( !attrs.id ) {42 //if an id is not supplied, create a random id.43 id = 'legend-' + Math.random();44 } else {45 id = attrs.id;46 }47 if ( attrs.columns ) {48 columns = +attrs.columns;49 }50 if ( attrs.padding ) {51 padding = +attrs.padding;52 }53 paddingStr = padding + '';54 svg = document.createElementNS( svgNamespace, 'svg' );55 if ( attrs.width ) {56 svg.setAttribute( 'width', width + '' );57 }58 if ( attrs.height ) {59 svg.setAttribute( 'height', height + '' );60 }61 svg.setAttribute( 'id', id );62 if ( attrs.x ) {63 x = +attrs.x;64 }65 if ( attrs.y ) {66 y = +attrs.y;67 }68 element.append( svg );69 g = document.createElementNS( svgNamespace, 'g' );70 g.setAttribute( 'transform', 'translate(' + x + ',' + y + ')' );71 svg.appendChild( g );72 if ( attrs.labels ) {73 labels = scope.$eval( attrs.labels );74 }75 if ( attrs.styles ) {76 styles = scope.$eval( attrs.styles );77 }78 if ( attrs.classes ) {79 classes = scope.$eval( attrs.classes );80 }81 if ( attrs.shapes ) {82 shapes = scope.$eval( attrs.shapes );83 }84 for ( var i in labels ) {85 if ( labels.hasOwnProperty( i ) ) {86 var shpe = shapes[ i ],87 shape, text, textSize, g1;88 if ( columnTracker % columns === 0 ) {89 widthTracker = 0;90 heightTracker = heightTracker + ( padding + padding * 1.5 );91 }92 g1 = document.createElementNS( svgNamespace, 'g' );93 g1.setAttribute( 'transform', 'translate(' + widthTracker + ', ' + heightTracker + ')' );94 if ( shpe === 'rect' ) {95 shape = document.createElementNS( svgNamespace, 'rect' );96 //x, y, rx, ry97 shape.setAttribute( 'y', 0 - padding / 2 + '' );98 shape.setAttribute( 'width', paddingStr );99 shape.setAttribute( 'height', paddingStr );100 } else if ( shpe === 'ellipse' ) {101 shape = document.createElementNS( svgNamespace, 'ellipse' );102 shape.setAttribute( 'rx', paddingStr );103 shape.setAttribute( 'ry', padding + padding / 2 + '' );104 } else {105 shape = document.createElementNS( svgNamespace, 'circle' );106 shape.setAttribute( 'r', padding / 2 + '' );107 }108 if ( styles && styles[ i ] ) {109 shape.setAttribute( 'style', styles[ i ] );110 }111 if ( classes && classes[ i ] ) {112 shape.setAttribute( 'class', classes[ i ] );113 }114 g1.appendChild( shape );115 widthTracker = widthTracker + shape.clientWidth + ( padding + padding / 2 );116 text = document.createElementNS( svgNamespace, 'text' );117 text.setAttribute( 'transform', 'translate(10, 5)' );118 text.appendChild( document.createTextNode( labels[ i ] ) );119 g1.appendChild( text );120 g.appendChild( g1 );121 textSize = text.clientWidth;122 widthTracker = widthTracker + textSize + ( padding + padding * 0.75 );123 columnTracker++;124 }125 }126 };127 }128 };129 } ).directive( 'nvd3Legend', [130 function () {131 var margin, width, height, id;132 return {133 restrict: 'EA',134 scope: {135 data: '=',136 id: '@',137 margin: '&',138 width: '@',139 height: '@',140 key: '&',141 color: '&',142 align: '@',143 rightalign: '@',144 updatestate: '@',145 radiobuttonmode: '@',146 x: '&',147 y: '&'148 },149 link: function ( scope, element, attrs ) {150 scope.$watch( 'data', function ( data ) {151 if ( data ) {152 if ( scope.chart ) {153 return d3.select( '#' + attrs.id + ' svg' ).attr( 'height', height ).attr( 'width', width ).datum( data ).transition().duration( 250 ).call( scope.chart );154 }155 margin = scope.$eval( attrs.margin ) || {156 top: 5,157 right: 0,158 bottom: 5,159 left: 0160 };161 width = attrs.width === undefined ? element[ 0 ].parentElement.offsetWidth - ( margin.left + margin.right ) : +attrs.width - ( margin.left + margin.right );162 height = attrs.height === undefined ? element[ 0 ].parentElement.offsetHeight - ( margin.top + margin.bottom ) : +attrs.height - ( margin.top + margin.bottom );163 if ( width === undefined || width < 0 ) {164 width = 400;165 }166 if ( height === undefined || height < 0 ) {167 height = 20;168 }169 if ( !attrs.id ) {170 //if an id is not supplied, create a random id.171 id = 'legend-' + Math.random();172 } else {173 id = attrs.id;174 }175 nv.addGraph( {176 generate: function () {177 var chart = nv.models.legend().width( width ).height( height ).margin( margin ).align( attrs.align === undefined ? true : attrs.align === 'true' ).rightAlign( attrs.rightalign === undefined ? true : attrs.rightalign === 'true' ).updateState( attrs.updatestate === undefined ? true : attrs.updatestate === 'true' ).radioButtonMode( attrs.radiobuttonmode === undefined ? false : attrs.radiobuttonmode === 'true' ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).key( attrs.key === undefined ? function ( d ) {178 return d.key;179 } : scope.key() );180 if ( !d3.select( '#' + attrs.id + ' svg' )[ 0 ][ 0 ] ) {181 d3.select( '#' + attrs.id ).append( 'svg' );182 }183 d3.select( '#' + attrs.id + ' svg' ).attr( 'height', height ).attr( 'width', width ).datum( data ).transition().duration( 250 ).call( chart );184 nv.utils.windowResize( chart.update );185 scope.chart = chart;186 return chart;187 }188 } );189 }190 } );191 }192 };193 }194 ] );195 function initializeLegendMargin( scope, attrs ) {196 var margin = ( scope.$eval( attrs.legendmargin ) || {197 left: 0,198 top: 5,199 bottom: 5,200 right: 0201 } );202 if ( typeof ( margin ) !== 'object' ) {203 // we were passed a vanilla int, convert to full margin object204 margin = {205 left: margin,206 top: margin,207 bottom: margin,208 right: margin209 };210 }211 scope.legendmargin = margin;212 }213 function configureLegend( chart, scope, attrs ) {214 if ( chart.legend && attrs.showlegend && ( attrs.showlegend === 'true' ) ) {215 initializeLegendMargin( scope, attrs );216 chart.legend.margin( scope.legendmargin );217 chart.legend.width( attrs.legendwidth === undefined ? 400 : ( +attrs.legendwidth ) );218 chart.legend.height( attrs.legendheight === undefined ? 20 : ( +attrs.legendheight ) );219 chart.legend.key( attrs.legendkey === undefined ? function ( d ) {220 return d.key;221 } : scope.legendkey() );222 chart.legend.color( attrs.legendcolor === undefined ? nv.utils.defaultColor() : scope.legendcolor() );223 chart.legend.align( attrs.legendalign === undefined ? true : ( attrs.legendalign === 'true' ) );224 chart.legend.rightAlign( attrs.legendrightalign === undefined ? true : ( attrs.legendrightalign === 'true' ) );225 chart.legend.updateState( attrs.legendupdatestate === undefined ? true : ( attrs.legendupdatestate === 'true' ) );226 chart.legend.radioButtonMode( attrs.legendradiobuttonmode === undefined ? false : ( attrs.legendradiobuttonmode === 'true' ) );227 }228 }229 function processEvents( chart, scope ) {230 if ( chart.dispatch ) {231 if ( chart.dispatch.tooltipShow ) {232 chart.dispatch.on( 'tooltipShow.directive', function ( event ) {233 scope.$emit( 'tooltipShow.directive', event );234 } );235 }236 if ( chart.dispatch.tooltipHide ) {237 chart.dispatch.on( 'tooltipHide.directive', function ( event ) {238 scope.$emit( 'tooltipHide.directive', event );239 } );240 }241 if ( chart.dispatch.beforeUpdate ) {242 chart.dispatch.on( 'beforeUpdate.directive', function ( event ) {243 scope.$emit( 'beforeUpdate.directive', event );244 } );245 }246 if ( chart.dispatch.stateChange ) {247 chart.dispatch.on( 'stateChange.directive', function ( event ) {248 scope.$emit( 'stateChange.directive', event );249 } );250 }251 if ( chart.dispatch.changeState ) {252 chart.dispatch.on( 'changeState.directive', function ( event ) {253 scope.$emit( 'changeState.directive', event );254 } );255 }256 }257 if ( chart.lines ) {258 chart.lines.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {259 scope.$emit( 'elementMouseover.tooltip.directive', event );260 } );261 chart.lines.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {262 scope.$emit( 'elementMouseout.tooltip.directive', event );263 } );264 chart.lines.dispatch.on( 'elementClick.directive', function ( event ) {265 scope.$emit( 'elementClick.directive', event );266 } );267 }268 if ( chart.stacked && chart.stacked.dispatch ) {269 chart.stacked.dispatch.on( 'areaClick.toggle.directive', function ( event ) {270 scope.$emit( 'areaClick.toggle.directive', event );271 } );272 chart.stacked.dispatch.on( 'tooltipShow.directive', function ( event ) {273 scope.$emit( 'tooltipShow.directive', event );274 } );275 chart.stacked.dispatch.on( 'tooltipHide.directive', function ( event ) {276 scope.$emit( 'tooltipHide.directive', event );277 } );278 }279 if ( chart.interactiveLayer ) {280 if ( chart.interactiveLayer.elementMouseout ) {281 chart.interactiveLayer.dispatch.on( 'elementMouseout.directive', function ( event ) {282 scope.$emit( 'elementMouseout.directive', event );283 } );284 }285 if ( chart.interactiveLayer.elementMousemove ) {286 chart.interactiveLayer.dispatch.on( 'elementMousemove.directive', function ( event ) {287 scope.$emit( 'elementMousemove.directive', event );288 } );289 }290 }291 if ( chart.discretebar ) {292 chart.discretebar.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {293 scope.$emit( 'elementMouseover.tooltip.directive', event );294 } );295 chart.discretebar.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {296 scope.$emit( 'elementMouseover.tooltip.directive', event );297 } );298 chart.discretebar.dispatch.on( 'elementClick.directive', function ( event ) {299 scope.$emit( 'elementClick.directive', event );300 } );301 }302 if ( chart.multibar ) {303 chart.multibar.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {304 scope.$emit( 'elementMouseover.tooltip.directive', event );305 } );306 chart.multibar.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {307 scope.$emit( 'elementMouseover.tooltip.directive', event );308 } );309 chart.multibar.dispatch.on( 'elementClick.directive', function ( event ) {310 scope.$emit( 'elementClick.directive', event );311 } );312 }313 if ( chart.pie ) {314 chart.pie.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {315 scope.$emit( 'elementMouseover.tooltip.directive', event );316 } );317 chart.pie.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {318 scope.$emit( 'elementMouseover.tooltip.directive', event );319 } );320 chart.pie.dispatch.on( 'elementClick.directive', function ( event ) {321 scope.$emit( 'elementClick.directive', event );322 } );323 }324 if ( chart.scatter ) {325 chart.scatter.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {326 scope.$emit( 'elementMouseover.tooltip.directive', event );327 } );328 chart.scatter.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {329 scope.$emit( 'elementMouseover.tooltip.directive', event );330 } );331 }332 if ( chart.bullet ) {333 chart.bullet.dispatch.on( 'elementMouseover.tooltip.directive', function ( event ) {334 scope.$emit( 'elementMouseover.tooltip.directive', event );335 } );336 chart.bullet.dispatch.on( 'elementMouseout.tooltip.directive', function ( event ) {337 scope.$emit( 'elementMouseover.tooltip.directive', event );338 } );339 }340 if ( chart.legend ) {341 //'legendClick', 'legendDblclick', 'legendMouseover'342 //stateChange343 chart.legend.dispatch.on( 'stateChange.legend.directive', function ( event ) {344 scope.$emit( 'stateChange.legend.directive', event );345 } );346 chart.legend.dispatch.on( 'legendClick.directive', function ( d, i ) {347 scope.$emit( 'legendClick.directive', d, i );348 } );349 chart.legend.dispatch.on( 'legendDblclick.directive', function ( d, i ) {350 scope.$emit( 'legendDblclick.directive', d, i );351 } );352 chart.legend.dispatch.on( 'legendMouseover.directive', function ( d, i ) {353 scope.$emit( 'legendMouseover.directive', d, i );354 } );355 }356 if ( chart.controls ) {357 if ( chart.controls.legendClick ) {358 chart.controls.dispatch.on( 'legendClick.directive', function ( d, i ) {359 scope.$emit( 'legendClick.directive', d, i );360 } );361 }362 }363 }364 function configureXaxis( chart, scope, attrs ) {365 if ( attrs.xaxisorient ) {366 chart.xAxis.orient( attrs.xaxisorient );367 }368 if ( attrs.xaxisticks ) {369 chart.xAxis.scale().ticks( attrs.xaxisticks );370 }371 if ( attrs.xaxistickvalues ) {372 if ( Array.isArray( scope.$eval( attrs.xaxistickvalues ) ) ) {373 chart.xAxis.tickValues( scope.$eval( attrs.xaxistickvalues ) );374 } else if ( typeof scope.xaxistickvalues() === 'function' ) {375 chart.xAxis.tickValues( scope.xaxistickvalues() );376 }377 }378 if ( attrs.xaxisticksubdivide ) {379 chart.xAxis.tickSubdivide( scope.xaxisticksubdivide() );380 }381 if ( attrs.xaxisticksize ) {382 chart.xAxis.tickSize( scope.xaxisticksize() );383 }384 if ( attrs.xaxistickpadding ) {385 chart.xAxis.tickPadding( scope.xaxistickpadding() );386 }387 if ( attrs.xaxistickformat ) {388 chart.xAxis.tickFormat( scope.xaxistickformat() );389 }390 if ( attrs.xaxislabel ) {391 chart.xAxis.axisLabel( attrs.xaxislabel );392 }393 if ( attrs.xaxisscale ) {394 chart.xAxis.scale( scope.xaxisscale() );395 }396 if ( attrs.xaxisdomain ) {397 if ( Array.isArray( scope.$eval( attrs.xaxisdomain ) ) ) {398 chart.xDomain( scope.$eval( attrs.xaxisdomain ) );399 } else if ( typeof scope.xaxisdomain() === 'function' ) {400 chart.xDomain( scope.xaxisdomain() );401 }402 }403 if ( attrs.xaxisrange ) {404 if ( Array.isArray( scope.$eval( attrs.xaxisrange ) ) ) {405 chart.xRange( scope.$eval( attrs.xaxisrange ) );406 } else if ( typeof scope.xaxisrange() === 'function' ) {407 chart.xRange( scope.xaxisrange() );408 }409 }410 if ( attrs.xaxisrangeband ) {411 chart.xAxis.rangeBand( scope.xaxisrangeband() );412 }413 if ( attrs.xaxisrangebands ) {414 chart.xAxis.rangeBands( scope.xaxisrangebands() );415 }416 if ( attrs.xaxisshowmaxmin ) {417 chart.xAxis.showMaxMin( ( attrs.xaxisshowmaxmin === 'true' ) );418 }419 if ( attrs.xaxishighlightzero ) {420 chart.xAxis.highlightZero( ( attrs.xaxishighlightzero === 'true' ) );421 }422 if ( attrs.xaxisrotatelabels ) {423 chart.xAxis.rotateLabels( ( +attrs.xaxisrotatelabels ) );424 }425 // if(attrs.xaxisrotateylabel){426 // chart.xAxis.rotateYLabel((attrs.xaxisrotateylabel === "true"));427 // }428 if ( attrs.xaxisstaggerlabels ) {429 chart.xAxis.staggerLabels( ( attrs.xaxisstaggerlabels === 'true' ) );430 }431 if ( attrs.xaxislabeldistance ) {432 chart.xAxis.axisLabelDistance( ( +attrs.xaxislabeldistance ) );433 }434 }435 function configureX2axis( chart, scope, attrs ) {436 if ( attrs.x2axisorient ) {437 chart.x2Axis.orient( attrs.x2axisorient );438 }439 if ( attrs.x2axisticks ) {440 chart.x2Axis.scale().ticks( attrs.x2axisticks );441 }442 if ( attrs.x2axistickvalues ) {443 if ( Array.isArray( scope.$eval( attrs.x2axistickvalues ) ) ) {444 chart.x2Axis.tickValues( scope.$eval( attrs.x2axistickvalues ) );445 } else if ( typeof scope.xaxistickvalues() === 'function' ) {446 chart.x2Axis.tickValues( scope.x2axistickvalues() );447 }448 }449 if ( attrs.x2axisticksubdivide ) {450 chart.x2Axis.tickSubdivide( scope.x2axisticksubdivide() );451 }452 if ( attrs.x2axisticksize ) {453 chart.x2Axis.tickSize( scope.x2axisticksize() );454 }455 if ( attrs.x2axistickpadding ) {456 chart.x2Axis.tickPadding( scope.x2axistickpadding() );457 }458 if ( attrs.x2axistickformat ) {459 chart.x2Axis.tickFormat( scope.x2axistickformat() );460 }461 if ( attrs.x2axislabel ) {462 chart.x2Axis.axisLabel( attrs.x2axislabel );463 }464 if ( attrs.x2axisscale ) {465 chart.x2Axis.scale( scope.x2axisscale() );466 }467 if ( attrs.x2axisdomain ) {468 if ( Array.isArray( scope.$eval( attrs.x2axisdomain ) ) ) {469 chart.x2Axis.domain( scope.$eval( attrs.x2axisdomain ) );470 } else if ( typeof scope.x2axisdomain() === 'function' ) {471 chart.x2Axis.domain( scope.x2axisdomain() );472 }473 }474 if ( attrs.x2axisrange ) {475 if ( Array.isArray( scope.$eval( attrs.x2axisrange ) ) ) {476 chart.x2Axis.range( scope.$eval( attrs.x2axisrange ) );477 } else if ( typeof scope.x2axisrange() === 'function' ) {478 chart.x2Axis.range( scope.x2axisrange() );479 }480 }481 if ( attrs.x2axisrangeband ) {482 chart.x2Axis.rangeBand( scope.x2axisrangeband() );483 }484 if ( attrs.x2axisrangebands ) {485 chart.x2Axis.rangeBands( scope.x2axisrangebands() );486 }487 if ( attrs.x2axisshowmaxmin ) {488 chart.x2Axis.showMaxMin( ( attrs.x2axisshowmaxmin === 'true' ) );489 }490 if ( attrs.x2axishighlightzero ) {491 chart.x2Axis.highlightZero( ( attrs.x2axishighlightzero === 'true' ) );492 }493 if ( attrs.x2axisrotatelables ) {494 chart.x2Axis.rotateLabels( ( +attrs.x2axisrotatelables ) );495 }496 // if(attrs.xaxisrotateylabel){497 // chart.xAxis.rotateYLabel((attrs.xaxisrotateylabel === "true"));498 // }499 if ( attrs.x2axisstaggerlabels ) {500 chart.x2Axis.staggerLabels( ( attrs.x2axisstaggerlabels === 'true' ) );501 }502 if ( attrs.x2axislabeldistance ) {503 chart.x2Axis.axisLabelDistance( ( +attrs.x2axislabeldistance ) );504 }505 }506 function configureYaxis( chart, scope, attrs ) {507 if ( attrs.yaxisorient ) {508 chart.yAxis.orient( attrs.yaxisorient );509 }510 if ( attrs.yaxisticks ) {511 chart.yAxis.scale().ticks( attrs.yaxisticks );512 }513 if ( attrs.yaxistickvalues ) {514 if ( Array.isArray( scope.$eval( attrs.yaxistickvalues ) ) ) {515 chart.yAxis.tickValues( scope.$eval( attrs.yaxistickvalues ) );516 } else if ( typeof scope.yaxistickvalues() === 'function' ) {517 chart.yAxis.tickValues( scope.yaxistickvalues() );518 }519 }520 if ( attrs.yaxisticksubdivide ) {521 chart.yAxis.tickSubdivide( scope.yaxisticksubdivide() );522 }523 if ( attrs.yaxisticksize ) {524 chart.yAxis.tickSize( scope.yaxisticksize() );525 }526 if ( attrs.yaxistickpadding ) {527 chart.yAxis.tickPadding( scope.yaxistickpadding() );528 }529 if ( attrs.yaxistickformat ) {530 chart.yAxis.tickFormat( scope.yaxistickformat() );531 }532 if ( attrs.yaxislabel ) {533 chart.yAxis.axisLabel( attrs.yaxislabel );534 }535 if ( attrs.yaxisscale ) {536 chart.yAxis.scale( scope.yaxisscale() );537 }538 if ( attrs.yaxisdomain ) {539 if ( Array.isArray( scope.$eval( attrs.yaxisdomain ) ) ) {540 chart.yDomain( scope.$eval( attrs.yaxisdomain ) );541 } else if ( typeof scope.yaxisdomain() === 'function' ) {542 chart.yDomain( scope.yaxisdomain() );543 }544 }545 if ( attrs.yaxisrange ) {546 if ( Array.isArray( scope.$eval( attrs.yaxisrange ) ) ) {547 chart.yRange( scope.$eval( attrs.yaxisrange ) );548 } else if ( typeof scope.yaxisrange() === 'function' ) {549 chart.yRange( scope.yaxisrange() );550 }551 }552 if ( attrs.yaxisrangeband ) {553 chart.yAxis.rangeBand( scope.yaxisrangeband() );554 }555 if ( attrs.yaxisrangebands ) {556 chart.yAxis.rangeBands( scope.yaxisrangebands() );557 }558 if ( attrs.yaxisshowmaxmin ) {559 chart.yAxis.showMaxMin( ( attrs.yaxisshowmaxmin === 'true' ) );560 }561 if ( attrs.yaxishighlightzero ) {562 chart.yAxis.highlightZero( ( attrs.yaxishighlightzero === 'true' ) );563 }564 if ( attrs.yaxisrotatelabels ) {565 chart.yAxis.rotateLabels( ( +attrs.yaxisrotatelabels ) );566 }567 if ( attrs.yaxisrotateylabel ) {568 chart.yAxis.rotateYLabel( ( attrs.yaxisrotateylabel === 'true' ) );569 }570 if ( attrs.yaxisstaggerlabels ) {571 chart.yAxis.staggerLabels( ( attrs.yaxisstaggerlabels === 'true' ) );572 }573 if ( attrs.yaxislabeldistance ) {574 chart.yAxis.axisLabelDistance( ( +attrs.yaxislabeldistance ) );575 }576 }577 function configureY1axis( chart, scope, attrs ) {578 if ( attrs.y1axisticks ) {579 chart.y1Axis.scale().ticks( attrs.y1axisticks );580 }581 if ( attrs.y1axistickvalues ) {582 if ( Array.isArray( scope.$eval( attrs.y1axistickvalues ) ) ) {583 chart.y1Axis.tickValues( scope.$eval( attrs.y1axistickvalues ) );584 } else if ( typeof scope.y1axistickvalues() === 'function' ) {585 chart.y1Axis.tickValues( scope.y1axistickvalues() );586 }587 }588 if ( attrs.y1axisticksubdivide ) {589 chart.y1Axis.tickSubdivide( scope.y1axisticksubdivide() );590 }591 if ( attrs.y1axisticksize ) {592 chart.y1Axis.tickSize( scope.y1axisticksize() );593 }594 if ( attrs.y1axistickpadding ) {595 chart.y1Axis.tickPadding( scope.y1axistickpadding() );596 }597 if ( attrs.y1axistickformat ) {598 chart.y1Axis.tickFormat( scope.y1axistickformat() );599 }600 if ( attrs.y1axislabel ) {601 chart.y1Axis.axisLabel( attrs.y1axislabel );602 }603 if ( attrs.y1axisscale ) {604 chart.y1Axis.yScale( scope.y1axisscale() );605 }606 if ( attrs.y1axisdomain ) {607 if ( Array.isArray( scope.$eval( attrs.y1axisdomain ) ) ) {608 chart.y1Axis.domain( scope.$eval( attrs.y1axisdomain ) );609 } else if ( typeof scope.y1axisdomain() === 'function' ) {610 chart.y1Axis.domain( scope.y1axisdomain() );611 }612 }613 if ( attrs.y1axisrange ) {614 if ( Array.isArray( scope.$eval( attrs.y1axisrange ) ) ) {615 chart.y1Axis.range( scope.$eval( attrs.y1axisrange ) );616 } else if ( typeof scope.y1axisrange() === 'function' ) {617 chart.y1Axis.range( scope.y1axisrange() );618 }619 }620 if ( attrs.y1axisrangeband ) {621 chart.y1Axis.rangeBand( scope.y1axisrangeband() );622 }623 if ( attrs.y1axisrangebands ) {624 chart.y1Axis.rangeBands( scope.y1axisrangebands() );625 }626 if ( attrs.y1axisshowmaxmin ) {627 chart.y1Axis.showMaxMin( ( attrs.y1axisshowmaxmin === 'true' ) );628 }629 if ( attrs.y1axishighlightzero ) {630 chart.y1Axis.highlightZero( ( attrs.y1axishighlightzero === 'true' ) );631 }632 if ( attrs.y1axisrotatelabels ) {633 chart.y1Axis.rotateLabels( ( +scope.y1axisrotatelabels ) );634 }635 if ( attrs.y1axisrotateylabel ) {636 chart.y1Axis.rotateYLabel( ( attrs.y1axisrotateylabel === 'true' ) );637 }638 if ( attrs.y1axisstaggerlabels ) {639 chart.y1Axis.staggerlabels( ( attrs.y1axisstaggerlabels === 'true' ) );640 }641 if ( attrs.y1axislabeldistance ) {642 chart.y1Axis.axisLabelDistance( ( +attrs.y1axislabeldistance ) );643 }644 }645 function configureY2axis( chart, scope, attrs ) {646 if ( attrs.y2axisticks ) {647 chart.y2Axis.scale().ticks( attrs.y2axisticks );648 }649 if ( attrs.y2axistickvalues ) {650 chart.y2Axis.tickValues( scope.$eval( attrs.y2axistickvalues ) );651 }652 if ( attrs.y2axisticksubdivide ) {653 chart.y2Axis.tickSubdivide( scope.y2axisticksubdivide() );654 }655 if ( attrs.y2axisticksize ) {656 chart.y2Axis.tickSize( scope.y2axisticksize() );657 }658 if ( attrs.y2axistickpadding ) {659 chart.y2Axis.tickPadding( scope.y2axistickpadding() );660 }661 if ( attrs.y2axistickformat ) {662 chart.y2Axis.tickFormat( scope.y2axistickformat() );663 }664 if ( attrs.y2axislabel ) {665 chart.y2Axis.axisLabel( attrs.y2axislabel );666 }667 if ( attrs.y2axisscale ) {668 chart.y2Axis.yScale( scope.y2axisscale() );669 }670 if ( attrs.y2axisdomain ) {671 if ( Array.isArray( scope.$eval( attrs.y2axisdomain ) ) ) {672 chart.y2Axis.domain( scope.$eval( attrs.y2axisdomain ) );673 } else if ( typeof scope.y2axisdomain() === 'function' ) {674 chart.y2Axis.domain( scope.y2axisdomain() );675 }676 }677 if ( attrs.y2axisrange ) {678 if ( Array.isArray( scope.$eval( attrs.y2axisrange ) ) ) {679 chart.y2Axis.range( scope.$eval( attrs.y2axisrange ) );680 } else if ( typeof scope.y2axisrange() === 'function' ) {681 chart.y2Axis.range( scope.y2axisrange() );682 }683 }684 if ( attrs.y2axisrangeband ) {685 chart.y2Axis.rangeBand( scope.y2axisrangeband() );686 }687 if ( attrs.y2axisrangebands ) {688 chart.y2Axis.rangeBands( scope.y2axisrangebands() );689 }690 if ( attrs.y2axisshowmaxmin ) {691 chart.y2Axis.showMaxMin( ( attrs.y2axisshowmaxmin === 'true' ) );692 }693 if ( attrs.y2axishighlightzero ) {694 chart.y2Axis.highlightZero( ( attrs.y2axishighlightzero === 'true' ) );695 }696 if ( attrs.y2axisrotatelabels ) {697 chart.y2Axis.rotateLabels( ( +scope.y2axisrotatelabels ) );698 }699 if ( attrs.y2axisrotateylabel ) {700 chart.y2Axis.rotateYLabel( ( attrs.y2axisrotateylabel === 'true' ) );701 }702 if ( attrs.y2axisstaggerlabels ) {703 chart.y2Axis.staggerlabels( ( attrs.y2axisstaggerlabels === 'true' ) );704 }705 if ( attrs.y2axislabeldistance ) {706 chart.y2Axis.axisLabelDistance( ( +attrs.y2axislabeldistance ) );707 }708 }709 function initializeMargin( scope, attrs ) {710 var margin = scope.$eval( attrs.margin ) || {711 left: 50,712 top: 50,713 bottom: 50,714 right: 50715 };716 if ( typeof margin !== 'object' ) {717 // we were passed a vanilla int, convert to full margin object718 margin = {719 left: margin,720 top: margin,721 bottom: margin,722 right: margin723 };724 }725 scope.margin = margin;726 }727 function checkElementID( scope, attrs, element, chart, data ) {728 configureXaxis( chart, scope, attrs );729 configureX2axis( chart, scope, attrs );730 configureYaxis( chart, scope, attrs );731 configureY1axis( chart, scope, attrs );732 configureY2axis( chart, scope, attrs );733 configureLegend( chart, scope, attrs );734 processEvents( chart, scope );735 var dataAttributeChartID;736 //randomly generated if id attribute doesn't exist737 if ( !attrs.id ) {738 dataAttributeChartID = 'chartid' + Math.floor( Math.random() * 1000000001 );739 angular.element( element ).attr( 'data-chartid', dataAttributeChartID );740 //if an id is not supplied, create a random id.741 if ( d3.select( '[data-chartid=' + dataAttributeChartID + '] svg' ).empty() ) {742 d3.select( '[data-chartid=' + dataAttributeChartID + ']' ).append( 'svg' ).attr( 'height', scope.height ).attr( 'width', scope.width ).datum( data ).transition().duration( attrs.transitionduration === undefined ? 250 : +attrs.transitionduration ).call( chart );743 } else {744 d3.select( '[data-chartid=' + dataAttributeChartID + '] svg' ).attr( 'height', scope.height ).attr( 'width', scope.width ).datum( data ).transition().duration( attrs.transitionduration === undefined ? 250 : +attrs.transitionduration ).call( chart );745 }746 } else {747 if ( angular.isArray( data ) && data.length === 0 ) {748 d3.select( '#' + attrs.id + ' svg' ).remove();749 }750 if ( d3.select( '#' + attrs.id + ' svg' ).empty() ) {751 d3.select( '#' + attrs.id ).append( 'svg' );752 }753 d3.select( '#' + attrs.id + ' svg' ).attr( 'height', scope.height ).attr( 'width', scope.width ).datum( data ).transition().duration( attrs.transitionduration === undefined ? 250 : +attrs.transitionduration ).call( chart );754 }755 }756 angular.module( 'nvd3ChartDirectives', [] ).directive( 'nvd3LineChart', [757 function () {758 return {759 restrict: 'EA',760 scope: {761 data: '=',762 width: '@',763 height: '@',764 id: '@',765 showlegend: '@',766 tooltips: '@',767 showxaxis: '@',768 showyaxis: '@',769 rightalignyaxis: '@',770 defaultstate: '@',771 nodata: '@',772 margin: '&',773 tooltipcontent: '&',774 color: '&',775 x: '&',776 y: '&',777 forcex: '@',778 forcey: '@',779 isArea: '@',780 interactive: '@',781 clipedge: '@',782 clipvoronoi: '@',783 interpolate: '@',784 callback: '&',785 useinteractiveguideline: '@',786 xaxisorient: '&',787 xaxisticks: '@',788 xaxistickvalues: '&xaxistickvalues',789 xaxisticksubdivide: '&',790 xaxisticksize: '&',791 xaxistickpadding: '&',792 xaxistickformat: '&',793 xaxislabel: '@',794 xaxisscale: '&',795 xaxisdomain: '&',796 xaxisrange: '&',797 xaxisrangeband: '&',798 xaxisrangebands: '&',799 xaxisshowmaxmin: '@',800 xaxishighlightzero: '@',801 xaxisrotatelabels: '@',802 xaxisrotateylabel: '@',803 xaxisstaggerlabels: '@',804 xaxislabeldistance: '@',805 yaxisorient: '&',806 yaxisticks: '&',807 yaxistickvalues: '&yaxistickvalues',808 yaxisticksubdivide: '&',809 yaxisticksize: '&',810 yaxistickpadding: '&',811 yaxistickformat: '&',812 yaxislabel: '@',813 yaxisscale: '&',814 yaxisdomain: '&',815 yaxisrange: '&',816 yaxisrangeband: '&',817 yaxisrangebands: '&',818 yaxisshowmaxmin: '@',819 yaxishighlightzero: '@',820 yaxisrotatelabels: '@',821 yaxisrotateylabel: '@',822 yaxisstaggerlabels: '@',823 yaxislabeldistance: '@',824 legendmargin: '&',825 legendwidth: '@',826 legendheight: '@',827 legendkey: '@',828 legendcolor: '&',829 legendalign: '@',830 legendrightalign: '@',831 legendupdatestate: '@',832 legendradiobuttonmode: '@',833 objectequality: '@',834 transitionduration: '@'835 },836 controller: [837 '$scope',838 '$element',839 '$attrs',840 function ( $scope, $element, $attrs ) {841 $scope.d3Call = function ( data, chart ) {842 checkElementID( $scope, $attrs, $element, chart, data );843 };844 }845 ],846 link: function ( scope, element, attrs ) {847 scope.$watch( 'data', function ( data ) {848 if ( data ) {849 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.850 if ( scope.chart ) {851 return scope.d3Call( data, scope.chart );852 }853 nv.addGraph( {854 generate: function () {855 initializeMargin( scope, attrs );856 var chart = nv.models.lineChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {857 return d[ 0 ];858 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {859 return d[ 1 ];860 } : scope.y() ).forceX( attrs.forcex === undefined ? [] : scope.$eval( attrs.forcex ) ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).rightAlignYAxis( attrs.rightalignyaxis === undefined ? false : attrs.rightalignyaxis === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).clipEdge( attrs.clipedge === undefined ? false : attrs.clipedge === 'true' ).clipVoronoi( attrs.clipvoronoi === undefined ? false : attrs.clipvoronoi === 'true' ).interpolate( attrs.interpolate === undefined ? 'linear' : attrs.interpolate ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).isArea( attrs.isarea === undefined ? function ( d ) {861 return d.area;862 } : function () {863 return attrs.isarea === 'true';864 } );865 if ( chart.useInteractiveGuideline ) {866 chart.useInteractiveGuideline( attrs.useinteractiveguideline === undefined ? false : attrs.useinteractiveguideline === 'true' );867 }868 if ( attrs.tooltipcontent ) {869 chart.tooltipContent( scope.tooltipcontent() );870 }871 scope.d3Call( data, chart );872 nv.utils.windowResize( chart.update );873 scope.chart = chart;874 return chart;875 },876 callback: attrs.callback === undefined ? null : scope.callback()877 } );878 }879 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );880 }881 };882 }883 ] ).directive( 'nvd3CumulativeLineChart', [884 function () {885 return {886 restrict: 'EA',887 scope: {888 data: '=',889 width: '@',890 height: '@',891 id: '@',892 showlegend: '@',893 tooltips: '@',894 showxaxis: '@',895 showyaxis: '@',896 rightalignyaxis: '@',897 defaultstate: '@',898 nodata: '@',899 margin: '&',900 tooltipcontent: '&',901 color: '&',902 x: '&',903 y: '&',904 forcex: '@',905 forcey: '@',906 isArea: '@',907 interactive: '@',908 clipedge: '@',909 clipvoronoi: '@',910 usevoronoi: '@',911 average: '&',912 rescaley: '@',913 callback: '&',914 useinteractiveguideline: '@',915 xaxisorient: '&',916 xaxisticks: '&',917 xaxistickvalues: '&xaxistickvalues',918 xaxisticksubdivide: '&',919 xaxisticksize: '&',920 xaxistickpadding: '&',921 xaxistickformat: '&',922 xaxislabel: '@',923 xaxisscale: '&',924 xaxisdomain: '&',925 xaxisrange: '&',926 xaxisrangeband: '&',927 xaxisrangebands: '&',928 xaxisshowmaxmin: '@',929 xaxishighlightzero: '@',930 xaxisrotatelabels: '@',931 xaxisrotateylabel: '@',932 xaxisstaggerlabels: '@',933 xaxislabeldistance: '@',934 yaxisorient: '&',935 yaxisticks: '&',936 yaxistickvalues: '&yaxistickvalues',937 yaxisticksubdivide: '&',938 yaxisticksize: '&',939 yaxistickpadding: '&',940 yaxistickformat: '&',941 yaxislabel: '@',942 yaxisscale: '&',943 yaxisdomain: '&',944 yaxisrange: '&',945 yaxisrangeband: '&',946 yaxisrangebands: '&',947 yaxisshowmaxmin: '@',948 yaxishighlightzero: '@',949 yaxisrotatelabels: '@',950 yaxisrotateylabel: '@',951 yaxisstaggerlabels: '@',952 yaxislabeldistance: '@',953 legendmargin: '&',954 legendwidth: '@',955 legendheight: '@',956 legendkey: '@',957 legendcolor: '&',958 legendalign: '@',959 legendrightalign: '@',960 legendupdatestate: '@',961 legendradiobuttonmode: '@',962 objectequality: '@',963 transitionduration: '@'964 },965 controller: [966 '$scope',967 '$element',968 '$attrs',969 function ( $scope, $element, $attrs ) {970 $scope.d3Call = function ( data, chart ) {971 checkElementID( $scope, $attrs, $element, chart, data );972 };973 }974 ],975 link: function ( scope, element, attrs ) {976 scope.$watch( 'data', function ( data ) {977 if ( data ) {978 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.979 if ( scope.chart ) {980 return scope.d3Call( data, scope.chart );981 }982 nv.addGraph( {983 generate: function () {984 initializeMargin( scope, attrs );985 var chart = nv.models.cumulativeLineChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {986 return d[ 0 ];987 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {988 return d[ 1 ];989 } : scope.y() ).forceX( attrs.forcex === undefined ? [] : scope.$eval( attrs.forcex ) ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).rightAlignYAxis( attrs.rightalignyaxis === undefined ? false : attrs.rightalignyaxis === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).clipEdge( attrs.clipedge === undefined ? false : attrs.clipedge === 'true' ).clipVoronoi( attrs.clipvoronoi === undefined ? false : attrs.clipvoronoi === 'true' ).useVoronoi( attrs.usevoronoi === undefined ? false : attrs.usevoronoi === 'true' ).average( attrs.average === undefined ? function ( d ) {990 return d.average;991 } : scope.average() ).color( attrs.color === undefined ? d3.scale.category10().range() : scope.color() ).isArea( attrs.isarea === undefined ? function ( d ) {992 return d.area;993 } : attrs.isarea === 'true' );994 //.rescaleY(attrs.rescaley === undefined ? false : (attrs.rescaley === 'true'));995 if ( chart.useInteractiveGuideline ) {996 chart.useInteractiveGuideline( attrs.useinteractiveguideline === undefined ? false : attrs.useinteractiveguideline === 'true' );997 }998 if ( attrs.tooltipcontent ) {999 chart.tooltipContent( scope.tooltipcontent() );1000 }1001 scope.d3Call( data, chart );1002 nv.utils.windowResize( chart.update );1003 scope.chart = chart;1004 return chart;1005 },1006 callback: attrs.callback === undefined ? null : scope.callback()1007 } );1008 }1009 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1010 }1011 };1012 }1013 ] ).directive( 'nvd3StackedAreaChart', [1014 function () {1015 return {1016 restrict: 'EA',1017 scope: {1018 data: '=',1019 width: '@',1020 height: '@',1021 id: '@',1022 showlegend: '@',1023 tooltips: '@',1024 showcontrols: '@',1025 nodata: '@',1026 margin: '&',1027 tooltipcontent: '&',1028 color: '&',1029 x: '&',1030 y: '&',1031 forcex: '@',1032 forcey: '@',1033 forcesize: '@',1034 interactive: '@',1035 usevoronoi: '@',1036 clipedge: '@',1037 interpolate: '@',1038 style: '@',1039 order: '@',1040 offset: '@',1041 size: '&',1042 xScale: '&',1043 yScale: '&',1044 xDomain: '&',1045 yDomain: '&',1046 xRange: '&',1047 yRange: '&',1048 sizeDomain: '&',1049 callback: '&',1050 showxaxis: '&',1051 xaxisorient: '&',1052 xaxisticks: '&',1053 xaxistickvalues: '&xaxistickvalues',1054 xaxisticksubdivide: '&',1055 xaxisticksize: '&',1056 xaxistickpadding: '&',1057 xaxistickformat: '&',1058 xaxislabel: '@',1059 xaxisscale: '&',1060 xaxisdomain: '&',1061 xaxisrange: '&',1062 xaxisrangeband: '&',1063 xaxisrangebands: '&',1064 xaxisshowmaxmin: '@',1065 xaxishighlightzero: '@',1066 xaxisrotatelabels: '@',1067 xaxisrotateylabel: '@',1068 xaxisstaggerlabels: '@',1069 xaxisaxislabeldistance: '@',1070 showyaxis: '&',1071 useinteractiveguideline: '@',1072 yaxisorient: '&',1073 yaxisticks: '&',1074 yaxistickvalues: '&yaxistickvalues',1075 yaxisticksubdivide: '&',1076 yaxisticksize: '&',1077 yaxistickpadding: '&',1078 yaxistickformat: '&',1079 yaxislabel: '@',1080 yaxisscale: '&',1081 yaxisdomain: '&',1082 yaxisrange: '&',1083 yaxisrangeband: '&',1084 yaxisrangebands: '&',1085 yaxisshowmaxmin: '@',1086 yaxishighlightzero: '@',1087 yaxisrotatelabels: '@',1088 yaxisrotateylabel: '@',1089 yaxisstaggerlabels: '@',1090 yaxislabeldistance: '@',1091 legendmargin: '&',1092 legendwidth: '@',1093 legendheight: '@',1094 legendkey: '@',1095 legendcolor: '&',1096 legendalign: '@',1097 legendrightalign: '@',1098 legendupdatestate: '@',1099 legendradiobuttonmode: '@',1100 objectequality: '@',1101 transitionduration: '@'1102 },1103 controller: [1104 '$scope',1105 '$element',1106 '$attrs',1107 function ( $scope, $element, $attrs ) {1108 $scope.d3Call = function ( data, chart ) {1109 checkElementID( $scope, $attrs, $element, chart, data );1110 };1111 }1112 ],1113 link: function ( scope, element, attrs ) {1114 scope.$watch( 'data', function ( data ) {1115 if ( data ) {1116 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1117 if ( scope.chart ) {1118 return scope.d3Call( data, scope.chart );1119 }1120 nv.addGraph( {1121 generate: function () {1122 initializeMargin( scope, attrs );1123 var chart = nv.models.stackedAreaChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1124 return d[ 0 ];1125 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1126 return d[ 1 ];1127 } : scope.y() ).forceX( attrs.forcex === undefined ? [] : scope.$eval( attrs.forcex ) ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).size( attrs.size === undefined ? function ( d ) {1128 return d.size === undefined ? 1 : d.size;1129 } : scope.size() ).forceSize( attrs.forcesize === undefined ? [] : scope.$eval( attrs.forcesize ) ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).showControls( attrs.showcontrols === undefined ? false : attrs.showcontrols === 'true' ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).clipEdge( attrs.clipedge === undefined ? false : attrs.clipedge === 'true' ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() );1130 if ( chart.useInteractiveGuideline ) {1131 chart.useInteractiveGuideline( attrs.useinteractiveguideline === undefined ? false : attrs.useinteractiveguideline === 'true' );1132 }1133 if ( attrs.usevoronoi ) {1134 chart.useVoronoi( attrs.usevoronoi === 'true' );1135 }1136 if ( attrs.style ) {1137 chart.style( attrs.style );1138 }1139 if ( attrs.order ) {1140 chart.order( attrs.order );1141 }1142 if ( attrs.offset ) {1143 chart.offset( attrs.offset );1144 }1145 if ( attrs.interpolate ) {1146 chart.interpolate( attrs.interpolate );1147 }1148 if ( attrs.tooltipcontent ) {1149 chart.tooltipContent( scope.tooltipcontent() );1150 }1151 if ( attrs.xscale ) {1152 chart.xScale( scope.xscale() );1153 }1154 if ( attrs.yscale ) {1155 chart.yScale( scope.yscale() );1156 }1157 if ( attrs.xdomain ) {1158 if ( Array.isArray( scope.$eval( attrs.xdomain ) ) ) {1159 chart.xDomain( scope.$eval( attrs.xdomain ) );1160 } else if ( typeof scope.xdomain() === 'function' ) {1161 chart.xDomain( scope.xdomain() );1162 }1163 }1164 if ( attrs.ydomain ) {1165 if ( Array.isArray( scope.$eval( attrs.ydomain ) ) ) {1166 chart.yDomain( scope.$eval( attrs.ydomain ) );1167 } else if ( typeof scope.ydomain() === 'function' ) {1168 chart.yDomain( scope.ydomain() );1169 }1170 }1171 if ( attrs.sizedomain ) {1172 chart.sizeDomain( scope.sizedomain() );1173 }1174 scope.d3Call( data, chart );1175 nv.utils.windowResize( chart.update );1176 scope.chart = chart;1177 return chart;1178 },1179 callback: attrs.callback === undefined ? null : scope.callback()1180 } );1181 }1182 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1183 }1184 };1185 }1186 ] ).directive( 'nvd3MultiBarChart', [1187 function () {1188 return {1189 restrict: 'EA',1190 scope: {1191 data: '=',1192 width: '@',1193 height: '@',1194 id: '@',1195 showlegend: '@',1196 tooltips: '@',1197 tooltipcontent: '&',1198 color: '&',1199 showcontrols: '@',1200 nodata: '@',1201 reducexticks: '@',1202 staggerlabels: '@',1203 rotatelabels: '@',1204 margin: '&',1205 x: '&',1206 y: '&',1207 forcey: '@',1208 delay: '@',1209 stacked: '@',1210 callback: '&',1211 showxaxis: '&',1212 xaxisorient: '&',1213 xaxisticks: '&',1214 xaxistickvalues: '&xaxistickvalues',1215 xaxisticksubdivide: '&',1216 xaxisticksize: '&',1217 xaxistickpadding: '&',1218 xaxistickformat: '&',1219 xaxislabel: '@',1220 xaxisscale: '&',1221 xaxisdomain: '&',1222 xaxisrange: '&',1223 xaxisrangeband: '&',1224 xaxisrangebands: '&',1225 xaxisshowmaxmin: '@',1226 xaxishighlightzero: '@',1227 xaxisrotatelabels: '@',1228 xaxisrotateylabel: '@',1229 xaxisstaggerlabels: '@',1230 xaxisaxislabeldistance: '@',1231 showyaxis: '&',1232 yaxisorient: '&',1233 yaxisticks: '&',1234 yaxistickvalues: '&yaxistickvalues',1235 yaxisticksubdivide: '&',1236 yaxisticksize: '&',1237 yaxistickpadding: '&',1238 yaxistickformat: '&',1239 yaxislabel: '@',1240 yaxisscale: '&',1241 yaxisdomain: '&',1242 yaxisrange: '&',1243 yaxisrangeband: '&',1244 yaxisrangebands: '&',1245 yaxisshowmaxmin: '@',1246 yaxishighlightzero: '@',1247 yaxisrotatelabels: '@',1248 yaxisrotateylabel: '@',1249 yaxisstaggerlabels: '@',1250 yaxislabeldistance: '@',1251 legendmargin: '&',1252 legendwidth: '@',1253 legendheight: '@',1254 legendkey: '@',1255 legendcolor: '&',1256 legendalign: '@',1257 legendrightalign: '@',1258 legendupdatestate: '@',1259 legendradiobuttonmode: '@',1260 objectequality: '@',1261 transitionduration: '@'1262 },1263 controller: [1264 '$scope',1265 '$element',1266 '$attrs',1267 function ( $scope, $element, $attrs ) {1268 $scope.d3Call = function ( data, chart ) {1269 checkElementID( $scope, $attrs, $element, chart, data );1270 };1271 }1272 ],1273 link: function ( scope, element, attrs ) {1274 scope.$watch( 'data', function ( data ) {1275 if ( data ) {1276 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1277 if ( scope.chart ) {1278 return scope.d3Call( data, scope.chart );1279 }1280 nv.addGraph( {1281 generate: function () {1282 initializeMargin( scope, attrs );1283 var chart = nv.models.multiBarChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1284 return d[ 0 ];1285 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1286 return d[ 1 ];1287 } : scope.y() ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).showControls( attrs.showcontrols === undefined ? false : attrs.showcontrols === 'true' ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).reduceXTicks( attrs.reducexticks === undefined ? false : attrs.reducexticks === 'true' ).staggerLabels( attrs.staggerlabels === undefined ? false : attrs.staggerlabels === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).rotateLabels( attrs.rotatelabels === undefined ? 0 : attrs.rotatelabels ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).delay( attrs.delay === undefined ? 1200 : attrs.delay ).stacked( attrs.stacked === undefined ? false : attrs.stacked === 'true' );1288 if ( attrs.tooltipcontent ) {1289 chart.tooltipContent( scope.tooltipcontent() );1290 }1291 scope.d3Call( data, chart );1292 nv.utils.windowResize( chart.update );1293 scope.chart = chart;1294 return chart;1295 },1296 callback: attrs.callback === undefined ? null : scope.callback()1297 } );1298 }1299 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1300 }1301 };1302 }1303 ] ).directive( 'nvd3DiscreteBarChart', [1304 function () {1305 return {1306 restrict: 'EA',1307 scope: {1308 data: '=',1309 width: '@',1310 height: '@',1311 id: '@',1312 tooltips: '@',1313 showxaxis: '@',1314 showyaxis: '@',1315 tooltipcontent: '&',1316 staggerlabels: '@',1317 color: '&',1318 margin: '&',1319 nodata: '@',1320 x: '&',1321 y: '&',1322 forcey: '@',1323 showvalues: '@',1324 valueformat: '&',1325 callback: '&',1326 xaxisorient: '&',1327 xaxisticks: '&',1328 xaxistickvalues: '&xaxistickvalues',1329 xaxisticksubdivide: '&',1330 xaxisticksize: '&',1331 xaxistickpadding: '&',1332 xaxistickformat: '&',1333 xaxislabel: '@',1334 xaxisscale: '&',1335 xaxisdomain: '&',1336 xaxisrange: '&',1337 xaxisrangeband: '&',1338 xaxisrangebands: '&',1339 xaxisshowmaxmin: '@',1340 xaxishighlightzero: '@',1341 xaxisrotatelabels: '@',1342 xaxisrotateylabel: '@',1343 xaxisstaggerlabels: '@',1344 xaxisaxislabeldistance: '@',1345 yaxisorient: '&',1346 yaxisticks: '&',1347 yaxistickvalues: '&yaxistickvalues',1348 yaxisticksubdivide: '&',1349 yaxisticksize: '&',1350 yaxistickpadding: '&',1351 yaxistickformat: '&',1352 yaxislabel: '@',1353 yaxisscale: '&',1354 yaxisdomain: '&',1355 yaxisrange: '&',1356 yaxisrangeband: '&',1357 yaxisrangebands: '&',1358 yaxisshowmaxmin: '@',1359 yaxishighlightzero: '@',1360 yaxisrotatelabels: '@',1361 yaxisrotateylabel: '@',1362 yaxisstaggerlabels: '@',1363 yaxislabeldistance: '@',1364 legendmargin: '&',1365 legendwidth: '@',1366 legendheight: '@',1367 legendkey: '@',1368 legendcolor: '&',1369 legendalign: '@',1370 legendrightalign: '@',1371 legendupdatestate: '@',1372 legendradiobuttonmode: '@',1373 objectequality: '@',1374 transitionduration: '@'1375 },1376 controller: [1377 '$scope',1378 '$element',1379 '$attrs',1380 function ( $scope, $element, $attrs ) {1381 $scope.d3Call = function ( data, chart ) {1382 checkElementID( $scope, $attrs, $element, chart, data );1383 };1384 }1385 ],1386 link: function ( scope, element, attrs ) {1387 scope.$watch( 'data', function ( data ) {1388 if ( data ) {1389 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1390 if ( scope.chart ) {1391 return scope.d3Call( data, scope.chart );1392 }1393 nv.addGraph( {1394 generate: function () {1395 initializeMargin( scope, attrs );1396 var chart = nv.models.discreteBarChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1397 return d[ 0 ];1398 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1399 return d[ 1 ];1400 } : scope.y() ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).showValues( attrs.showvalues === undefined ? false : attrs.showvalues === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).staggerLabels( attrs.staggerlabels === undefined ? false : attrs.staggerlabels === 'true' ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() );1401 if ( attrs.tooltipcontent ) {1402 chart.tooltipContent( scope.tooltipcontent() );1403 }1404 if ( attrs.valueformat ) {1405 chart.valueFormat( scope.valueformat() );1406 }1407 scope.d3Call( data, chart );1408 nv.utils.windowResize( chart.update );1409 scope.chart = chart;1410 return chart;1411 },1412 callback: attrs.callback === undefined ? null : scope.callback()1413 } );1414 }1415 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1416 }1417 };1418 }1419 ] ).directive( 'nvd3HistoricalBarChart', [1420 function () {1421 return {1422 restrict: 'EA',1423 scope: {1424 data: '=',1425 width: '@',1426 height: '@',1427 id: '@',1428 tooltips: '@',1429 tooltipcontent: '&',1430 color: '&',1431 margin: '&',1432 nodata: '@',1433 x: '&',1434 y: '&',1435 forcey: '@',1436 isarea: '@',1437 interactive: '@',1438 clipedge: '@',1439 clipvoronoi: '@',1440 interpolate: '@',1441 highlightPoint: '@',1442 clearHighlights: '@',1443 callback: '&',1444 useinteractiveguideline: '@',1445 xaxisorient: '&',1446 xaxisticks: '&',1447 xaxistickvalues: '&xaxistickvalues',1448 xaxisticksubdivide: '&',1449 xaxisticksize: '&',1450 xaxistickpadding: '&',1451 xaxistickformat: '&',1452 xaxislabel: '@',1453 xaxisscale: '&',1454 xaxisdomain: '&',1455 xaxisrange: '&',1456 xaxisrangeband: '&',1457 xaxisrangebands: '&',1458 xaxisshowmaxmin: '@',1459 xaxishighlightzero: '@',1460 xaxisrotatelabels: '@',1461 xaxisrotateylabel: '@',1462 xaxisstaggerlabels: '@',1463 xaxisaxislabeldistance: '@',1464 yaxisorient: '&',1465 yaxisticks: '&',1466 yaxistickvalues: '&yaxistickvalues',1467 yaxisticksubdivide: '&',1468 yaxisticksize: '&',1469 yaxistickpadding: '&',1470 yaxistickformat: '&',1471 yaxislabel: '@',1472 yaxisscale: '&',1473 yaxisdomain: '&',1474 yaxisrange: '&',1475 yaxisrangeband: '&',1476 yaxisrangebands: '&',1477 yaxisshowmaxmin: '@',1478 yaxishighlightzero: '@',1479 yaxisrotatelabels: '@',1480 yaxisrotateylabel: '@',1481 yaxisstaggerlabels: '@',1482 yaxislabeldistance: '@',1483 legendmargin: '&',1484 legendwidth: '@',1485 legendheight: '@',1486 legendkey: '@',1487 legendcolor: '&',1488 legendalign: '@',1489 legendrightalign: '@',1490 legendupdatestate: '@',1491 legendradiobuttonmode: '@',1492 objectequality: '@',1493 transitionduration: '@'1494 },1495 controller: [1496 '$scope',1497 '$element',1498 '$attrs',1499 function ( $scope, $element, $attrs ) {1500 $scope.d3Call = function ( data, chart ) {1501 checkElementID( $scope, $attrs, $element, chart, data );1502 };1503 }1504 ],1505 link: function ( scope, element, attrs ) {1506 scope.$watch( 'data', function ( data ) {1507 if ( data ) {1508 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1509 if ( scope.chart ) {1510 return scope.d3Call( data, scope.chart );1511 }1512 nv.addGraph( {1513 generate: function () {1514 initializeMargin( scope, attrs );1515 var chart = nv.models.historicalBarChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1516 return d[ 0 ];1517 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1518 return d[ 1 ];1519 } : scope.y() ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() );1520 if ( chart.useInteractiveGuideline ) {1521 chart.useInteractiveGuideline( attrs.useinteractiveguideline === undefined ? false : attrs.useinteractiveguideline === 'true' );1522 }1523 if ( attrs.tooltipcontent ) {1524 chart.tooltipContent( scope.tooltipcontent() );1525 }1526 if ( attrs.valueformat ) {1527 chart.valueFormat( scope.valueformat() );1528 }1529 scope.d3Call( data, chart );1530 nv.utils.windowResize( chart.update );1531 scope.chart = chart;1532 return chart;1533 },1534 callback: attrs.callback === undefined ? null : scope.callback()1535 } );1536 }1537 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1538 }1539 };1540 }1541 ] ).directive( 'nvd3MultiBarHorizontalChart', [1542 function () {1543 return {1544 restrict: 'EA',1545 scope: {1546 data: '=',1547 width: '@',1548 height: '@',1549 id: '@',1550 showlegend: '@',1551 tooltips: '@',1552 tooltipcontent: '&',1553 color: '&',1554 showcontrols: '@',1555 margin: '&',1556 nodata: '@',1557 x: '&',1558 y: '&',1559 forcey: '@',1560 stacked: '@',1561 showvalues: '@',1562 valueformat: '&',1563 callback: '&',1564 xaxisorient: '&',1565 xaxisticks: '&',1566 xaxistickvalues: '&xaxistickvalues',1567 xaxisticksubdivide: '&',1568 xaxisticksize: '&',1569 xaxistickpadding: '&',1570 xaxistickformat: '&',1571 xaxislabel: '@',1572 xaxisscale: '&',1573 xaxisdomain: '&',1574 xaxisrange: '&',1575 xaxisrangeband: '&',1576 xaxisrangebands: '&',1577 xaxisshowmaxmin: '@',1578 xaxishighlightzero: '@',1579 xaxisrotatelabels: '@',1580 xaxisrotateylabel: '@',1581 xaxisstaggerlabels: '@',1582 xaxisaxislabeldistance: '@',1583 yaxisorient: '&',1584 yaxisticks: '&',1585 yaxistickvalues: '&yaxistickvalues',1586 yaxisticksubdivide: '&',1587 yaxisticksize: '&',1588 yaxistickpadding: '&',1589 yaxistickformat: '&',1590 yaxislabel: '@',1591 yaxisscale: '&',1592 yaxisdomain: '&',1593 yaxisrange: '&',1594 yaxisrangeband: '&',1595 yaxisrangebands: '&',1596 yaxisshowmaxmin: '@',1597 yaxishighlightzero: '@',1598 yaxisrotatelabels: '@',1599 yaxisrotateylabel: '@',1600 yaxisstaggerlabels: '@',1601 yaxislabeldistance: '@',1602 legendmargin: '&',1603 legendwidth: '@',1604 legendheight: '@',1605 legendkey: '@',1606 legendcolor: '&',1607 legendalign: '@',1608 legendrightalign: '@',1609 legendupdatestate: '@',1610 legendradiobuttonmode: '@',1611 objectequality: '@',1612 transitionduration: '@'1613 },1614 controller: [1615 '$scope',1616 '$element',1617 '$attrs',1618 function ( $scope, $element, $attrs ) {1619 $scope.d3Call = function ( data, chart ) {1620 checkElementID( $scope, $attrs, $element, chart, data );1621 };1622 }1623 ],1624 link: function ( scope, element, attrs ) {1625 scope.$watch( 'data', function ( data ) {1626 if ( data ) {1627 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1628 if ( scope.chart ) {1629 return scope.d3Call( data, scope.chart );1630 }1631 nv.addGraph( {1632 generate: function () {1633 initializeMargin( scope, attrs );1634 var chart = nv.models.multiBarHorizontalChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1635 return d[ 0 ];1636 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1637 return d[ 1 ];1638 } : scope.y() ).showXAxis( attrs.showxaxis === undefined ? false : attrs.showxaxis === 'true' ).showYAxis( attrs.showyaxis === undefined ? false : attrs.showyaxis === 'true' ).forceY( attrs.forcey === undefined ? [ 0 ] : scope.$eval( attrs.forcey ) ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).showControls( attrs.showcontrols === undefined ? false : attrs.showcontrols === 'true' ).showValues( attrs.showvalues === undefined ? false : attrs.showvalues === 'true' ).stacked( attrs.stacked === undefined ? false : attrs.stacked === 'true' );1639 if ( attrs.tooltipcontent ) {1640 chart.tooltipContent( scope.tooltipcontent() );1641 }1642 if ( attrs.valueformat ) {1643 chart.valueFormat( scope.valueformat() );1644 }1645 scope.d3Call( data, chart );1646 nv.utils.windowResize( chart.update );1647 scope.chart = chart;1648 return chart;1649 },1650 callback: attrs.callback === undefined ? null : scope.callback()1651 } );1652 }1653 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1654 }1655 };1656 }1657 ] ).directive( 'nvd3PieChart', [1658 function () {1659 return {1660 restrict: 'EA',1661 scope: {1662 data: '=',1663 width: '@',1664 height: '@',1665 id: '@',1666 showlabels: '@',1667 showlegend: '@',1668 donutLabelsOutside: '@',1669 pieLabelsOutside: '@',1670 labelType: '@',1671 nodata: '@',1672 margin: '&',1673 x: '&',1674 y: '&',1675 color: '&',1676 donut: '@',1677 donutRatio: '@',1678 labelthreshold: '@',1679 description: '&',1680 tooltips: '@',1681 tooltipcontent: '&',1682 valueFormat: '&',1683 callback: '&',1684 legendmargin: '&',1685 legendwidth: '@',1686 legendheight: '@',1687 legendkey: '@',1688 legendcolor: '&',1689 legendalign: '@',1690 legendrightalign: '@',1691 legendupdatestate: '@',1692 legendradiobuttonmode: '@',1693 objectequality: '@',1694 transitionduration: '@'1695 },1696 controller: [1697 '$scope',1698 '$element',1699 '$attrs',1700 function ( $scope, $element, $attrs ) {1701 $scope.d3Call = function ( data, chart ) {1702 checkElementID( $scope, $attrs, $element, chart, data );1703 };1704 }1705 ],1706 link: function ( scope, element, attrs ) {1707 scope.$watch( 'data', function ( data ) {1708 if ( data ) {1709 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1710 if ( scope.chart ) {1711 return scope.d3Call( data, scope.chart );1712 }1713 nv.addGraph( {1714 generate: function () {1715 initializeMargin( scope, attrs );1716 var chart = nv.models.pieChart().x( attrs.x === undefined ? function ( d ) {1717 return d[ 0 ];1718 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1719 return d[ 1 ];1720 } : scope.y() ).width( scope.width ).height( scope.height ).margin( scope.margin ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).showLabels( attrs.showlabels === undefined ? false : attrs.showlabels === 'true' ).labelThreshold( attrs.labelthreshold === undefined ? 0.02 : attrs.labelthreshold ).labelType( attrs.labeltype === undefined ? 'key' : attrs.labeltype ).pieLabelsOutside( attrs.pielabelsoutside === undefined ? true : attrs.pielabelsoutside === 'true' ).valueFormat( attrs.valueformat === undefined ? d3.format( ',.2f' ) : attrs.valueformat ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).description( attrs.description === undefined ? function ( d ) {1721 return d.description;1722 } : scope.description() ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).donutLabelsOutside( attrs.donutlabelsoutside === undefined ? false : attrs.donutlabelsoutside === 'true' ).donut( attrs.donut === undefined ? false : attrs.donut === 'true' ).donutRatio( attrs.donutratio === undefined ? 0.5 : attrs.donutratio );1723 if ( attrs.tooltipcontent ) {1724 chart.tooltipContent( scope.tooltipcontent() );1725 }1726 scope.d3Call( data, chart );1727 nv.utils.windowResize( chart.update );1728 scope.chart = chart;1729 return chart;1730 },1731 callback: attrs.callback === undefined ? null : scope.callback()1732 } );1733 }1734 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1735 }1736 };1737 }1738 ] ).directive( 'nvd3ScatterChart', [1739 function () {1740 return {1741 restrict: 'EA',1742 scope: {1743 data: '=',1744 width: '@',1745 height: '@',1746 id: '@',1747 showlegend: '@',1748 tooltips: '@',1749 showcontrols: '@',1750 showDistX: '@',1751 showDistY: '@',1752 rightAlignYAxis: '@',1753 fisheye: '@',1754 xPadding: '@',1755 yPadding: '@',1756 tooltipContent: '&',1757 tooltipXContent: '&',1758 tooltipYContent: '&',1759 color: '&',1760 margin: '&',1761 nodata: '@',1762 transitionDuration: '@',1763 shape: '&',1764 onlyCircles: '@',1765 interactive: '@',1766 x: '&',1767 y: '&',1768 size: '&',1769 forceX: '@',1770 forceY: '@',1771 forceSize: '@',1772 xrange: '&',1773 xdomain: '&',1774 xscale: '&',1775 yrange: '&',1776 ydomain: '&',1777 yscale: '&',1778 sizerange: '&',1779 sizedomain: '&',1780 zscale: '&',1781 callback: '&',1782 xaxisorient: '&',1783 xaxisticks: '&',1784 xaxistickvalues: '&xaxistickvalues',1785 xaxisticksubdivide: '&',1786 xaxisticksize: '&',1787 xaxistickpadding: '&',1788 xaxistickformat: '&',1789 xaxislabel: '@',1790 xaxisscale: '&',1791 xaxisdomain: '&',1792 xaxisrange: '&',1793 xaxisrangeband: '&',1794 xaxisrangebands: '&',1795 xaxisshowmaxmin: '@',1796 xaxishighlightzero: '@',1797 xaxisrotatelabels: '@',1798 xaxisrotateylabel: '@',1799 xaxisstaggerlabels: '@',1800 xaxisaxislabeldistance: '@',1801 yaxisorient: '&',1802 yaxisticks: '&',1803 yaxistickvalues: '&yaxistickvalues',1804 yaxisticksubdivide: '&',1805 yaxisticksize: '&',1806 yaxistickpadding: '&',1807 yaxistickformat: '&',1808 yaxislabel: '@',1809 yaxisscale: '&',1810 yaxisdomain: '&',1811 yaxisrange: '&',1812 yaxisrangeband: '&',1813 yaxisrangebands: '&',1814 yaxisshowmaxmin: '@',1815 yaxishighlightzero: '@',1816 yaxisrotatelabels: '@',1817 yaxisrotateylabel: '@',1818 yaxisstaggerlabels: '@',1819 yaxislabeldistance: '@',1820 legendmargin: '&',1821 legendwidth: '@',1822 legendheight: '@',1823 legendkey: '@',1824 legendcolor: '&',1825 legendalign: '@',1826 legendrightalign: '@',1827 legendupdatestate: '@',1828 legendradiobuttonmode: '@',1829 objectequality: '@',1830 transitionduration: '@'1831 },1832 controller: [1833 '$scope',1834 '$element',1835 '$attrs',1836 function ( $scope, $element, $attrs ) {1837 $scope.d3Call = function ( data, chart ) {1838 checkElementID( $scope, $attrs, $element, chart, data );1839 };1840 }1841 ],1842 link: function ( scope, element, attrs ) {1843 scope.$watch( 'data', function ( data ) {1844 if ( data ) {1845 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.1846 if ( scope.chart ) {1847 return scope.d3Call( data, scope.chart );1848 }1849 nv.addGraph( {1850 generate: function () {1851 initializeMargin( scope, attrs );1852 var chart = nv.models.scatterChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1853 return d.x;1854 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1855 return d.y;1856 } : scope.y() ).size( attrs.size === undefined ? function ( d ) {1857 return d.size === undefined ? 1 : d.size;1858 } : scope.size() ).forceX( attrs.forcex === undefined ? [] : scope.$eval( attrs.forcex ) ).forceY( attrs.forcey === undefined ? [] : scope.$eval( attrs.forcey ) ).forceSize( attrs.forcesize === undefined ? [] : scope.$eval( attrs.forcesize ) ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).tooltipContent( attrs.tooltipContent === undefined ? null : scope.tooltipContent() ).tooltipXContent( attrs.tooltipxcontent === undefined ? function ( key, x ) {1859 return '<strong>' + x + '</strong>';1860 } : scope.tooltipXContent() ).tooltipYContent( attrs.tooltipycontent === undefined ? function ( key, x, y ) {1861 return '<strong>' + y + '</strong>';1862 } : scope.tooltipYContent() ).showControls( attrs.showcontrols === undefined ? false : attrs.showcontrols === 'true' ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).showDistX( attrs.showdistx === undefined ? false : attrs.showdistx === 'true' ).showDistY( attrs.showdisty === undefined ? false : attrs.showdisty === 'true' ).xPadding( attrs.xpadding === undefined ? 0 : +attrs.xpadding ).yPadding( attrs.ypadding === undefined ? 0 : +attrs.ypadding ).fisheye( attrs.fisheye === undefined ? 0 : +attrs.fisheye ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).transitionDuration( attrs.transitionduration === undefined ? 250 : +attrs.transitionduration );1863 if ( attrs.shape ) {1864 chart.scatter.onlyCircles( false );1865 chart.scatter.shape( attrs.shape === undefined ? function ( d ) {1866 return d.shape || 'circle';1867 } : scope.shape() );1868 }1869 //'pointActive', 'clipVoronoi', 'clipRadius', 'useVoronoi'1870 if ( attrs.xdomain ) {1871 if ( Array.isArray( scope.$eval( attrs.xdomain ) ) ) {1872 chart.xDomain( scope.$eval( attrs.xdomain ) );1873 } else if ( typeof scope.xdomain() === 'function' ) {1874 chart.xDomain( scope.xdomain() );1875 }1876 }1877 if ( attrs.ydomain ) {1878 if ( Array.isArray( scope.$eval( attrs.ydomain ) ) ) {1879 chart.yDomain( scope.$eval( attrs.ydomain ) );1880 } else if ( typeof scope.ydomain() === 'function' ) {1881 chart.yDomain( scope.ydomain() );1882 }1883 }1884 if ( attrs.xscale ) {1885 chart.xDomain( scope.xdomain() );1886 chart.xRange( scope.xrange() );1887 chart.xScale( scope.xscale() );1888 }1889 if ( attrs.yscale ) {1890 chart.yDomain( scope.ydomain() );1891 chart.yRange( scope.yrange() );1892 chart.yScale( scope.yscale() );1893 }1894 if ( attrs.zscale ) {1895 chart.sizeDomain( scope.sizedomain() );1896 chart.sizeRange( scope.sizerange() );1897 chart.zScale( scope.zscale() );1898 }1899 scope.d3Call( data, chart );1900 nv.utils.windowResize( chart.update );1901 scope.chart = chart;1902 return chart;1903 },1904 callback: attrs.callback === undefined ? null : scope.callback()1905 } );1906 }1907 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );1908 }1909 };1910 }1911 ] ).directive( 'nvd3ScatterPlusLineChart', [1912 function () {1913 return {1914 restrict: 'EA',1915 scope: {1916 data: '=',1917 width: '@',1918 height: '@',1919 id: '@',1920 callback: '&'1921 },1922 controller: [1923 '$scope',1924 '$element',1925 '$attrs',1926 function ( $scope, $element, $attrs ) {1927 $scope.d3Call = function ( data, chart ) {1928 checkElementID( $scope, $attrs, $element, chart, data );1929 };1930 }1931 ],1932 link: function ( scope, element, attrs ) {1933 scope.$watch( 'data', function ( data ) {1934 if ( data ) {1935 if ( scope.chart ) {1936 return scope.d3Call( data, scope.chart );1937 }1938 nv.addGraph( {1939 generate: function () {1940 initializeMargin( scope, attrs );1941 var chart = nv.models.scatterPlusLineChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {1942 return d.x;1943 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {1944 return d.y;1945 } : scope.y() ).size( attrs.size === undefined ? function ( d ) {1946 return d.size === undefined ? 1 : d.size;1947 } : scope.size() ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).tooltipContent( attrs.tooltipContent === undefined ? null : scope.tooltipContent() ).tooltipXContent( attrs.tooltipxcontent === undefined ? function ( key, x ) {1948 return '<strong>' + x + '</strong>';1949 } : scope.tooltipXContent() ).tooltipYContent( attrs.tooltipycontent === undefined ? function ( key, x, y ) {1950 return '<strong>' + y + '</strong>';1951 } : scope.tooltipYContent() ).showControls( attrs.showcontrols === undefined ? false : attrs.showcontrols === 'true' ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).showDistX( attrs.showdistx === undefined ? false : attrs.showdistx === 'true' ).showDistY( attrs.showdisty === undefined ? false : attrs.showdisty === 'true' ).xPadding( attrs.xpadding === undefined ? 0 : +attrs.xpadding ).yPadding( attrs.ypadding === undefined ? 0 : +attrs.ypadding ).fisheye( attrs.fisheye === undefined ? 0 : +attrs.fisheye ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).transitionDuration( attrs.transitionduration === undefined ? 250 : +attrs.transitionduration );1952 if ( attrs.shape ) {1953 chart.scatter.onlyCircles( false );1954 chart.scatter.shape( attrs.shape === undefined ? function ( d ) {1955 return d.shape || 'circle';1956 } : scope.shape() );1957 }1958 scope.d3Call( data, chart );1959 nv.utils.windowResize( chart.update );1960 scope.chart = chart;1961 return chart;1962 },1963 callback: attrs.callback === undefined ? null : scope.callback()1964 } );1965 }1966 } );1967 }1968 };1969 }1970 ] ).directive( 'nvd3LinePlusBarChart', [1971 function () {1972 return {1973 restrict: 'EA',1974 scope: {1975 data: '=',1976 width: '@',1977 height: '@',1978 id: '@',1979 showlegend: '@',1980 tooltips: '@',1981 showxaxis: '@',1982 showyaxis: '@',1983 forceX: '@',1984 forceY: '@',1985 forceY2: '@',1986 rightalignyaxis: '@',1987 defaultstate: '@',1988 nodata: '@',1989 margin: '&',1990 tooltipcontent: '&',1991 color: '&',1992 x: '&',1993 y: '&',1994 clipvoronoi: '@',1995 interpolate: '@',1996 callback: '&',1997 xaxisorient: '&',1998 xaxisticks: '&',1999 xaxistickvalues: '&xaxistickvalues',2000 xaxisticksubdivide: '&',2001 xaxisticksize: '&',2002 xaxistickpadding: '&',2003 xaxistickformat: '&',2004 xaxislabel: '@',2005 xaxisscale: '&',2006 xaxisdomain: '&',2007 xaxisrange: '&',2008 xaxisrangeband: '&',2009 xaxisrangebands: '&',2010 xaxisshowmaxmin: '@',2011 xaxishighlightzero: '@',2012 xaxisrotatelabels: '@',2013 xaxisrotateylabel: '@',2014 xaxisstaggerlabels: '@',2015 xaxisaxislabeldistance: '@',2016 y1axisorient: '&',2017 y1axisticks: '&',2018 y1axistickvalues: '&y1axistickvalues',2019 y1axisticksubdivide: '&',2020 y1axisticksize: '&',2021 y1axistickpadding: '&',2022 y1axistickformat: '&',2023 y1axislabel: '@',2024 y1axisscale: '&',2025 y1axisdomain: '&',2026 y1axisrange: '&',2027 y1axisrangeband: '&',2028 y1axisrangebands: '&',2029 y1axisshowmaxmin: '@',2030 y1axishighlightzero: '@',2031 y1axisrotatelabels: '@',2032 y1axisrotateylabel: '@',2033 y1axisstaggerlabels: '@',2034 y1axisaxislabeldistance: '@',2035 y2axisorient: '&',2036 y2axisticks: '&',2037 y2axistickvalues: '&y2axistickvalues',2038 y2axisticksubdivide: '&',2039 y2axisticksize: '&',2040 y2axistickpadding: '&',2041 y2axistickformat: '&',2042 y2axislabel: '@',2043 y2axisscale: '&',2044 y2axisdomain: '&',2045 y2axisrange: '&',2046 y2axisrangeband: '&',2047 y2axisrangebands: '&',2048 y2axisshowmaxmin: '@',2049 y2axishighlightzero: '@',2050 y2axisrotatelabels: '@',2051 y2axisrotateylabel: '@',2052 y2axisstaggerlabels: '@',2053 y2axisaxislabeldistance: '@',2054 legendmargin: '&',2055 legendwidth: '@',2056 legendheight: '@',2057 legendkey: '@',2058 legendcolor: '&',2059 legendalign: '@',2060 legendrightalign: '@',2061 legendupdatestate: '@',2062 legendradiobuttonmode: '@',2063 objectequality: '@',2064 transitionduration: '@'2065 },2066 controller: [2067 '$scope',2068 '$element',2069 '$attrs',2070 function ( $scope, $element, $attrs ) {2071 $scope.d3Call = function ( data, chart ) {2072 checkElementID( $scope, $attrs, $element, chart, data );2073 };2074 }2075 ],2076 link: function ( scope, element, attrs ) {2077 scope.$watch( 'data', function ( data ) {2078 if ( data ) {2079 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.2080 if ( scope.chart ) {2081 return scope.d3Call( data, scope.chart );2082 }2083 nv.addGraph( {2084 generate: function () {2085 initializeMargin( scope, attrs );2086 var chart = nv.models.linePlusBarChart().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {2087 return d[ 0 ];2088 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {2089 return d[ 1 ];2090 } : scope.y() ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).interpolate( attrs.interpolate === undefined ? 'linear' : attrs.interpolate ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() );2091 if ( attrs.forcex ) {2092 chart.lines.forceX( scope.$eval( attrs.forcex ) );2093 chart.bars.forceX( scope.$eval( attrs.forcex ) );2094 }2095 if ( attrs.forcey ) {2096 chart.lines.forceY( scope.$eval( attrs.forcey ) );2097 chart.bars.forceY( scope.$eval( attrs.forcey ) );2098 }2099 if ( attrs.tooltipcontent ) {2100 chart.tooltipContent( scope.tooltipcontent() );2101 }2102 scope.d3Call( data, chart );2103 nv.utils.windowResize( chart.update );2104 scope.chart = chart;2105 return chart;2106 },2107 callback: attrs.callback === undefined ? null : scope.callback()2108 } );2109 }2110 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );2111 }2112 };2113 }2114 ] ).directive( 'nvd3LineWithFocusChart', [2115 function () {2116 return {2117 restrict: 'EA',2118 scope: {2119 data: '=',2120 width: '@',2121 height: '@',2122 height2: '@',2123 id: '@',2124 showlegend: '@',2125 tooltips: '@',2126 showxaxis: '@',2127 showyaxis: '@',2128 rightalignyaxis: '@',2129 defaultstate: '@',2130 nodata: '@',2131 margin: '&',2132 margin2: '&',2133 tooltipcontent: '&',2134 color: '&',2135 x: '&',2136 y: '&',2137 forceX: '@',2138 forceY: '@',2139 clipedge: '@',2140 clipvoronoi: '@',2141 interpolate: '@',2142 isArea: '@',2143 size: '&',2144 defined: '&',2145 interactive: '@',2146 callback: '&',2147 xaxisorient: '&',2148 xaxisticks: '&',2149 xaxistickvalues: '&xaxistickvalues',2150 xaxisticksubdivide: '&',2151 xaxisticksize: '&',2152 xaxistickpadding: '&',2153 xaxistickformat: '&',2154 xaxislabel: '@',2155 xaxisscale: '&',2156 xaxisdomain: '&',2157 xaxisrange: '&',2158 xaxisrangeband: '&',2159 xaxisrangebands: '&',2160 xaxisshowmaxmin: '@',2161 xaxishighlightzero: '@',2162 xaxisrotatelabels: '@',2163 xaxisrotateylabel: '@',2164 xaxisstaggerlabels: '@',2165 xaxisaxislabeldistance: '@',2166 x2axisorient: '&',2167 x2axisticks: '&',2168 x2axistickvalues: '&xaxistickvalues',2169 x2axisticksubdivide: '&',2170 x2axisticksize: '&',2171 x2axistickpadding: '&',2172 x2axistickformat: '&',2173 x2axislabel: '@',2174 x2axisscale: '&',2175 x2axisdomain: '&',2176 x2axisrange: '&',2177 x2axisrangeband: '&',2178 x2axisrangebands: '&',2179 x2axisshowmaxmin: '@',2180 x2axishighlightzero: '@',2181 x2axisrotatelables: '@',2182 x2axisrotateylabel: '@',2183 x2axisstaggerlabels: '@',2184 yaxisorient: '&',2185 yaxisticks: '&',2186 yaxistickvalues: '&yaxistickvalues',2187 yaxisticksubdivide: '&',2188 yaxisticksize: '&',2189 yaxistickpadding: '&',2190 yaxistickformat: '&',2191 yaxislabel: '@',2192 yaxisscale: '&',2193 yaxisdomain: '&',2194 yaxisrange: '&',2195 yaxisrangeband: '&',2196 yaxisrangebands: '&',2197 yaxisshowmaxmin: '@',2198 yaxishighlightzero: '@',2199 yaxisrotatelabels: '@',2200 yaxisrotateylabel: '@',2201 yaxisstaggerlabels: '@',2202 yaxislabeldistance: '@',2203 y2axisorient: '&',2204 y2axisticks: '&',2205 y2axistickvalues: '&',2206 y2axisticksubdivide: '&',2207 y2axisticksize: '&',2208 y2axistickpadding: '&',2209 y2axistickformat: '&',2210 y2axislabel: '@',2211 y2axisscale: '&',2212 y2axisdomain: '&',2213 y2axisrange: '&',2214 y2axisrangeband: '&',2215 y2axisrangebands: '&',2216 y2axisshowmaxmin: '@',2217 y2axishighlightzero: '@',2218 y2axisrotatelabels: '@',2219 y2axisrotateylabel: '@',2220 y2axisstaggerlabels: '@',2221 legendmargin: '&',2222 legendwidth: '@',2223 legendheight: '@',2224 legendkey: '@',2225 legendcolor: '&',2226 legendalign: '@',2227 legendrightalign: '@',2228 legendupdatestate: '@',2229 legendradiobuttonmode: '@',2230 objectequality: '@',2231 transitionduration: '@'2232 },2233 controller: [2234 '$scope',2235 '$element',2236 '$attrs',2237 function ( $scope, $element, $attrs ) {2238 $scope.d3Call = function ( data, chart ) {2239 checkElementID( $scope, $attrs, $element, chart, data );2240 };2241 }2242 ],2243 link: function ( scope, element, attrs ) {2244 scope.$watch( 'data', function ( data ) {2245 if ( data ) {2246 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.2247 if ( scope.chart ) {2248 return scope.d3Call( data, scope.chart );2249 }2250 nv.addGraph( {2251 generate: function () {2252 initializeMargin( scope, attrs );2253 //setup height 22254 //height 2 is 1002255 //margin2256 //nvd3 default is {top: 30, right: 30, bottom: 30, left: 60}2257 //setup margin 22258 //nvd3 default is {top: 0, right: 30, bottom: 20, left: 60}2259 if ( attrs.margin2 ) {2260 var margin2 = scope.$eval( attrs.margin2 );2261 if ( typeof margin2 !== 'object' ) {2262 // we were passed a vanilla int, convert to full margin object2263 margin2 = {2264 left: margin2,2265 top: margin2,2266 bottom: margin2,2267 right: margin22268 };2269 }2270 scope.margin2 = margin2;2271 } else {2272 scope.margin2 = {2273 top: 0,2274 right: 30,2275 bottom: 20,2276 left: 602277 };2278 }2279 //'xDomain', 'yDomain', 'xRange', 'yRange', ''clipEdge', 'clipVoronoi'2280 var chart = nv.models.lineWithFocusChart().width( scope.width ).height( scope.height ).height2( attrs.height2 === undefined ? 100 : +attrs.height2 ).margin( scope.margin ).margin2( scope.margin2 ).x( attrs.x === undefined ? function ( d ) {2281 return d[ 0 ];2282 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {2283 return d[ 1 ];2284 } : scope.y() ).forceX( attrs.forcex === undefined ? [] : scope.$eval( attrs.forcex ) ).forceY( attrs.forcey === undefined ? [] : scope.$eval( attrs.forcey ) ).showLegend( attrs.showlegend === undefined ? false : attrs.showlegend === 'true' ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata ).color( attrs.color === undefined ? nv.utils.defaultColor() : scope.color() ).isArea( attrs.isarea === undefined ? function ( d ) {2285 return d.area;2286 } : function () {2287 return attrs.isarea === 'true';2288 } ).size( attrs.size === undefined ? function ( d ) {2289 return d.size === undefined ? 1 : d.size;2290 } : scope.size() ).interactive( attrs.interactive === undefined ? false : attrs.interactive === 'true' ).interpolate( attrs.interpolate === undefined ? 'linear' : attrs.interpolate );2291 if ( attrs.defined ) {2292 chart.defined( scope.defined() );2293 }2294 if ( attrs.tooltipcontent ) {2295 chart.tooltipContent( scope.tooltipcontent() );2296 }2297 scope.d3Call( data, chart );2298 nv.utils.windowResize( chart.update );2299 scope.chart = chart;2300 return chart;2301 },2302 callback: attrs.callback === undefined ? null : scope.callback()2303 } );2304 }2305 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );2306 }2307 };2308 }2309 ] ).directive( 'nvd3BulletChart', [2310 function () {2311 return {2312 restrict: 'EA',2313 scope: {2314 data: '=',2315 width: '@',2316 height: '@',2317 id: '@',2318 margin: '&',2319 tooltips: '@',2320 tooltipcontent: '&',2321 orient: '@',2322 ranges: '&',2323 markers: '&',2324 measures: '&',2325 tickformat: '&',2326 nodata: '@',2327 callback: '&',2328 objectequality: '@',2329 transitionduration: '@'2330 },2331 controller: [2332 '$scope',2333 '$element',2334 '$attrs',2335 function ( $scope, $element, $attrs ) {2336 $scope.d3Call = function ( data, chart ) {2337 checkElementID( $scope, $attrs, $element, chart, data );2338 };2339 }2340 ],2341 link: function ( scope, element, attrs ) {2342 scope.$watch( 'data', function ( data ) {2343 if ( data ) {2344 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.2345 if ( scope.chart ) {2346 return scope.d3Call( data, scope.chart );2347 }2348 nv.addGraph( {2349 generate: function () {2350 initializeMargin( scope, attrs );2351 var chart = nv.models.bulletChart().width( scope.width ).height( scope.height ).margin( scope.margin ).orient( attrs.orient === undefined ? 'left' : attrs.orient ).tickFormat( attrs.tickformat === undefined ? null : scope.tickformat() ).tooltips( attrs.tooltips === undefined ? false : attrs.tooltips === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata );2352 if ( attrs.tooltipcontent ) {2353 chart.tooltipContent( scope.tooltipcontent() );2354 }2355 scope.d3Call( data, chart );2356 nv.utils.windowResize( chart.update );2357 scope.chart = chart;2358 return chart;2359 },2360 callback: attrs.callback === undefined ? null : scope.callback()2361 } );2362 }2363 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );2364 }2365 };2366 }2367 ] ).directive( 'nvd3SparklineChart', [2368 function () {2369 return {2370 restrict: 'EA',2371 scope: {2372 data: '=',2373 width: '@',2374 height: '@',2375 id: '@',2376 margin: '&',2377 x: '&',2378 y: '&',2379 color: '&',2380 xscale: '&',2381 yscale: '&',2382 showvalue: '@',2383 alignvalue: '@',2384 rightalignvalue: '@',2385 nodata: '@',2386 callback: '&',2387 xtickformat: '&',2388 ytickformat: '&',2389 objectequality: '@',2390 transitionduration: '@'2391 },2392 controller: [2393 '$scope',2394 '$element',2395 '$attrs',2396 function ( $scope, $element, $attrs ) {2397 $scope.d3Call = function ( data, chart ) {2398 checkElementID( $scope, $attrs, $element, chart, data );2399 };2400 }2401 ],2402 link: function ( scope, element, attrs ) {2403 scope.$watch( 'data', function ( data ) {2404 if ( data ) {2405 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.2406 if ( scope.chart ) {2407 return scope.d3Call( data, scope.chart );2408 }2409 nv.addGraph( {2410 generate: function () {2411 initializeMargin( scope, attrs );2412 var chart = nv.models.sparklinePlus().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {2413 return d.x;2414 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {2415 return d.y;2416 } : scope.y() ).xTickFormat( attrs.xtickformat === undefined ? d3.format( ',r' ) : scope.xtickformat() ).yTickFormat( attrs.ytickformat === undefined ? d3.format( ',.2f' ) : scope.ytickformat() ).color( attrs.color === undefined ? nv.utils.getColor( [ '#000' ] ) : scope.color() ).showValue( attrs.showvalue === undefined ? true : attrs.showvalue === 'true' ).alignValue( attrs.alignvalue === undefined ? true : attrs.alignvalue === 'true' ).rightAlignValue( attrs.rightalignvalue === undefined ? false : attrs.rightalignvalue === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata );2417 if ( attrs.xScale ) {2418 chart.xScale( scope.xScale() );2419 }2420 if ( attrs.yScale ) {2421 chart.yScale( scope.yScale() );2422 }2423 scope.d3Call( data, chart );2424 nv.utils.windowResize( chart.update );2425 scope.chart = chart;2426 return chart;2427 },2428 callback: attrs.callback === undefined ? null : scope.callback()2429 } );2430 }2431 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );2432 }2433 };2434 }2435 ] ).directive( 'nvd3SparklineWithBandlinesChart', [2436 function () {2437 /**2438 * http://www.perceptualedge.com/articles/visual_business_intelligence/introducing_bandlines.pdf2439 * You need five primary facts about a set of time-series values to construct a bandline:2440 * 1) the lowest value,2441 * 2) the 25th percentile (i.e., the point at and below which the lowest 25% of the values reside),2442 * 3) the median (a.k.a., the 50th percentile, the point at and below which 50% of the values reside),2443 * 4) the 75th percentile (i.e., the point at and below which 75% of the values reside), and2444 * 5) the highest value.2445 */2446 return {2447 restrict: 'EA',2448 scope: {2449 data: '=',2450 width: '@',2451 height: '@',2452 id: '@',2453 margin: '&',2454 x: '&',2455 y: '&',2456 color: '&',2457 xscale: '&',2458 yscale: '&',2459 showvalue: '@',2460 alignvalue: '@',2461 rightalignvalue: '@',2462 nodata: '@',2463 callback: '&',2464 xtickformat: '&',2465 ytickformat: '&',2466 objectequality: '@',2467 transitionduration: '@'2468 },2469 controller: [2470 '$scope',2471 '$element',2472 '$attrs',2473 function ( $scope, $element, $attrs ) {2474 //expect scope to contain bandlineProperties2475 $scope.d3Call = function ( data, chart ) {2476 var dataAttributeChartID;2477 //randomly generated if id attribute doesn't exist2478 var selectedChart;2479 var sLineSelection;2480 var bandlineData;2481 var bandLines;2482 if ( !$attrs.id ) {2483 dataAttributeChartID = 'chartid' + Math.floor( Math.random() * 1000000001 );2484 angular.element( $element ).attr( 'data-chartid', dataAttributeChartID );2485 selectedChart = d3.select( '[data-iem-chartid=' + dataAttributeChartID + '] svg' ).attr( 'height', $scope.height ).attr( 'width', $scope.width ).datum( data );2486 //chart.yScale()($scope.bandlineProperties.median)2487 //var sLineSelection = d3.select('svg#' + $attrs.id + ' g.nvd3.nv-wrap.nv-sparkline');2488 sLineSelection = d3.select( '[data-iem-chartid=' + dataAttributeChartID + '] svg' + ' g.nvd3.nv-wrap.nv-sparkline' );2489 bandlineData = [2490 $scope.bandlineProperties.min,2491 $scope.bandlineProperties.twentyFithPercentile,2492 $scope.bandlineProperties.median,2493 $scope.bandlineProperties.seventyFithPercentile,2494 $scope.bandlineProperties.max2495 ];2496 bandLines = sLineSelection.selectAll( '.nv-bandline' ).data( [ bandlineData ] );2497 bandLines.enter().append( 'g' ).attr( 'class', 'nv-bandline' );2498 selectedChart.transition().duration( $attrs.transitionduration === undefined ? 250 : +$attrs.transitionduration ).call( chart );2499 } else {2500 if ( !d3.select( '#' + $attrs.id + ' svg' ) ) {2501 d3.select( '#' + $attrs.id ).append( 'svg' );2502 }2503 selectedChart = d3.select( '#' + $attrs.id + ' svg' ).attr( 'height', $scope.height ).attr( 'width', $scope.width ).datum( data );2504 //chart.yScale()($scope.bandlineProperties.median)2505 sLineSelection = d3.select( 'svg#' + $attrs.id + ' g.nvd3.nv-wrap.nv-sparkline' );2506 bandlineData = [2507 $scope.bandlineProperties.min,2508 $scope.bandlineProperties.twentyFithPercentile,2509 $scope.bandlineProperties.median,2510 $scope.bandlineProperties.seventyFithPercentile,2511 $scope.bandlineProperties.max2512 ];2513 bandLines = sLineSelection.selectAll( '.nv-bandline' ).data( [ bandlineData ] );2514 bandLines.enter().append( 'g' ).attr( 'class', 'nv-bandline' );2515 selectedChart.transition().duration( $attrs.transitionduration === undefined ? 250 : +$attrs.transitionduration ).call( chart );2516 }2517 };2518 }2519 ],2520 link: function ( scope, element, attrs ) {2521 scope.$watch( 'data', function ( data ) {2522 if ( data ) {2523 //if the chart exists on the scope, do not call addGraph again, update data and call the chart.2524 if ( scope.chart ) {2525 return scope.d3Call( data, scope.chart );2526 }2527 nv.addGraph( {2528 generate: function () {2529 scope.bandlineProperties = {};2530 var sortedValues;2531 initializeMargin( scope, attrs );2532 var chart = nv.models.sparklinePlus().width( scope.width ).height( scope.height ).margin( scope.margin ).x( attrs.x === undefined ? function ( d ) {2533 return d.x;2534 } : scope.x() ).y( attrs.y === undefined ? function ( d ) {2535 return d.y;2536 } : scope.y() ).xTickFormat( attrs.xtickformat === undefined ? d3.format( ',r' ) : scope.xtickformat() ).yTickFormat( attrs.ytickformat === undefined ? d3.format( ',.2f' ) : scope.ytickformat() ).color( attrs.color === undefined ? nv.utils.getColor( [ '#000' ] ) : scope.color() ).showValue( attrs.showvalue === undefined ? true : attrs.showvalue === 'true' ).alignValue( attrs.alignvalue === undefined ? true : attrs.alignvalue === 'true' ).rightAlignValue( attrs.rightalignvalue === undefined ? false : attrs.rightalignvalue === 'true' ).noData( attrs.nodata === undefined ? 'No Data Available.' : scope.nodata );2537 //calc bandline data2538 scope.bandlineProperties.min = d3.min( data, function ( d ) {2539 return d[ 1 ];2540 } );2541 scope.bandlineProperties.max = d3.max( data, function ( d ) {2542 return d[ 1 ];2543 } );2544 sortedValues = data.map( function ( d ) {2545 return d[ 1 ];2546 } ).sort( function ( a, b ) {2547 if ( a[ 0 ] < b[ 0 ] ) {2548 return -1;2549 } else if ( a[ 0 ] === b[ 0 ] ) {2550 return 0;2551 } else {2552 return 1;2553 }2554 } );2555 scope.bandlineProperties.twentyFithPercentile = d3.quantile( sortedValues, 0.25 );2556 scope.bandlineProperties.median = d3.median( sortedValues );2557 scope.bandlineProperties.seventyFithPercentile = d3.quantile( sortedValues, 0.75 );2558 if ( attrs.xScale ) {2559 chart.xScale( scope.xScale() );2560 }2561 if ( attrs.yScale ) {2562 chart.yScale( scope.yScale() );2563 }2564 configureXaxis( chart, scope, attrs );2565 configureYaxis( chart, scope, attrs );2566 processEvents( chart, scope );2567 scope.d3Call( data, chart );2568 nv.utils.windowResize( chart.update );2569 scope.chart = chart;2570 return chart;2571 },2572 callback: attrs.callback === undefined ? null : scope.callback()2573 } );2574 }2575 }, attrs.objectequality === undefined ? false : attrs.objectequality === 'true' );2576 }2577 };2578 }2579 ] ); //still need to implement2580 //sparkbars??2581 //nv.models.multiBarTimeSeriesChart2582 //nv.models.multiChart2583 //nv.models.scatterPlusLineChart2584 //nv.models.linePlusBarWithFocusChart2585 //dual y-axis chart2586 //crossfilter using $services?...

Full Screen

Full Screen

_op_translations.py

Source:_op_translations.py Github

copy

Full Screen

1# Licensed to the Apache Software Foundation (ASF) under one2# or more contributor license agreements. See the NOTICE file3# distributed with this work for additional information4# regarding copyright ownership. The ASF licenses this file5# to you under the Apache License, Version 2.0 (the6# "License"); you may not use this file except in compliance7# with the License. You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing,12# software distributed under the License is distributed on an13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14# KIND, either express or implied. See the License for the15# specific language governing permissions and limitations16# under the License.17# coding: utf-818""" Module for translating ONNX operators into Mxnet operatoes"""19# pylint: disable=unused-argument,protected-access20import numpy as np21from . import _translation_utils as translation_utils22from .... import symbol23# Method definitions for the callable objects mapped in the import_helper module24def identity(attrs, inputs, proto_obj):25 """Returns the identity function of the input."""26 return 'identity', attrs, inputs27def random_uniform(attrs, inputs, proto_obj):28 """Draw random samples from a uniform distribtuion."""29 try:30 from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE31 except ImportError:32 raise ImportError("Onnx and protobuf need to be installed. "33 "Instructions to install - https://github.com/onnx/onnx")34 new_attrs = translation_utils._remove_attributes(attrs, ['seed'])35 new_attrs['dtype'] = TENSOR_TYPE_TO_NP_TYPE[int(new_attrs.get('dtype', 1))]36 return 'random_uniform', new_attrs, inputs37def random_normal(attrs, inputs, proto_obj):38 """Draw random samples from a Gaussian distribution."""39 try:40 from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE41 except ImportError:42 raise ImportError("Onnx and protobuf need to be installed. "43 "Instructions to install - https://github.com/onnx/onnx")44 new_attr = translation_utils._remove_attributes(attrs, ['seed'])45 new_attr = translation_utils._fix_attribute_names(new_attr, {'mean': 'loc'})46 new_attr['dtype'] = TENSOR_TYPE_TO_NP_TYPE[int(new_attr.get('dtype', 1))]47 return 'random_normal', new_attr, inputs48def sample_multinomial(attrs, inputs, proto_obj):49 """Draw random samples from a multinomial distribution."""50 try:51 from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE52 except ImportError:53 raise ImportError("Onnx and protobuf need to be installed. "54 + "Instructions to install - https://github.com/onnx/onnx")55 new_attrs = translation_utils._remove_attributes(attrs, ['seed'])56 new_attrs = translation_utils._fix_attribute_names(new_attrs, {'sample_size': 'shape'})57 new_attrs['dtype'] = TENSOR_TYPE_TO_NP_TYPE[int(attrs.get('dtype', 6))]58 return 'sample_multinomial', new_attrs, inputs59# Arithmetic Operations60def add(attrs, inputs, proto_obj):61 """Adding two tensors"""62 new_attr = {}63 if 'broadcast' in attrs and attrs['broadcast'] == 1:64 broadcast_axis = attrs['axis']65 op_value = translation_utils._fix_broadcast('broadcast_add', inputs,66 broadcast_axis, proto_obj)67 return op_value, new_attr, inputs68 return 'broadcast_add', new_attr, inputs69def subtract(attrs, inputs, proto_obj):70 """Subtracting two tensors"""71 new_attr = {}72 if 'broadcast' in attrs and attrs['broadcast'] == 1:73 broadcast_axis = attrs['axis']74 op_value = translation_utils._fix_broadcast('broadcast_sub', inputs,75 broadcast_axis, proto_obj)76 return op_value, new_attr, inputs77 return 'broadcast_sub', new_attr, inputs78def multiply(attrs, inputs, proto_obj):79 """Multiply two tensors"""80 new_attr = {}81 if 'broadcast' in attrs and attrs['broadcast'] == 1:82 broadcast_axis = attrs['axis']83 op_value = translation_utils._fix_broadcast('broadcast_mul', inputs,84 broadcast_axis, proto_obj)85 return op_value, new_attr, inputs86 return 'broadcast_mul', new_attr, inputs87def divide(attrs, inputs, proto_obj):88 """Divide two tensors"""89 new_attr = {}90 if 'broadcast' in attrs and attrs['broadcast'] == 1:91 broadcast_axis = attrs['axis']92 op_value = translation_utils._fix_broadcast('broadcast_div', inputs,93 broadcast_axis, proto_obj)94 return op_value, new_attr, inputs95 return 'broadcast_div', new_attr, inputs96def mean(attrs, inputs, proto_obj):97 """Mean of all the input tensors."""98 concat_input = [symbol.expand_dims(op_input, axis=0) for op_input in inputs]99 concat_sym = symbol.concat(*concat_input, dim=0)100 mean_sym = symbol.mean(concat_sym, axis=0)101 return mean_sym, attrs, inputs102def logical_and(attrs, inputs, proto_obj):103 """Logical and of two input arrays."""104 return 'broadcast_logical_and', attrs, inputs105def logical_or(attrs, inputs, proto_obj):106 """Logical or of two input arrays."""107 return 'broadcast_logical_or', attrs, inputs108def logical_xor(attrs, inputs, proto_obj):109 """Logical xor of two input arrays."""110 return 'broadcast_logical_xor', attrs, inputs111def logical_not(attrs, inputs, proto_obj):112 """Logical not of two input arrays."""113 return 'logical_not', attrs, inputs114def absolute(attrs, inputs, proto_obj):115 """Returns element-wise absolute value of the input."""116 return 'abs', attrs, inputs117def negative(attrs, inputs, proto_obj):118 """Negation of every element in a tensor"""119 return 'negative', attrs, inputs120def add_n(attrs, inputs, proto_obj):121 """Elementwise sum of arrays"""122 return 'add_n', attrs, inputs123# Sorting and Searching124def argmax(attrs, inputs, proto_obj):125 """Returns indices of the maximum values along an axis"""126 axis = attrs.get('axis', 0)127 keepdims = attrs.get('keepdims', 1)128 argmax_op = symbol.argmax(inputs[0], axis=axis, keepdims=keepdims)129 # onnx argmax operator always expects int64 as output type130 cast_attrs = {'dtype': 'int64'}131 return 'cast', cast_attrs, argmax_op132def argmin(attrs, inputs, proto_obj):133 """Returns indices of the minimum values along an axis."""134 axis = attrs.get('axis', 0)135 keepdims = attrs.get('keepdims', 1)136 argmin_op = symbol.argmin(inputs[0], axis=axis, keepdims=keepdims)137 # onnx argmax operator always expects int64 as output type138 cast_attrs = {'dtype': 'int64'}139 return 'cast', cast_attrs, argmin_op140def maximum(attrs, inputs, proto_obj):141 """142 Elementwise maximum of arrays.143 MXNet maximum compares only two symbols at a time.144 ONNX can send more than two to compare.145 Breaking into multiple mxnet ops to compare two symbols at a time146 """147 if len(inputs) > 1:148 mxnet_op = symbol.maximum(inputs[0], inputs[1])149 for op_input in inputs[2:]:150 mxnet_op = symbol.maximum(mxnet_op, op_input)151 else:152 mxnet_op = symbol.maximum(inputs[0], inputs[0])153 return mxnet_op, attrs, inputs154def minimum(attrs, inputs, proto_obj):155 """Elementwise minimum of arrays."""156 # MXNet minimum compares only two symbols at a time.157 # ONNX can send more than two to compare.158 # Breaking into multiple mxnet ops to compare two symbols at a time159 if len(inputs) > 1:160 mxnet_op = symbol.minimum(inputs[0], inputs[1])161 for op_input in inputs[2:]:162 mxnet_op = symbol.minimum(mxnet_op, op_input)163 else:164 mxnet_op = symbol.minimum(inputs[0], inputs[0])165 return mxnet_op, attrs, inputs166def lesser(attrs, inputs, proto_obj):167 """Logical Lesser operator with broadcasting."""168 return 'broadcast_lesser', attrs, inputs169def greater(attrs, inputs, proto_obj):170 """Logical Greater operator with broadcasting."""171 return 'broadcast_greater', attrs, inputs172def equal(attrs, inputs, proto_obj):173 """Logical Equal operator with broadcasting."""174 return 'broadcast_equal', attrs, inputs175#Hyperbolic functions176def tanh(attrs, inputs, proto_obj):177 """Returns the hyperbolic tangent of the input array."""178 return 'tanh', attrs, inputs179# Rounding180def ceil(attrs, inputs, proto_obj):181 """ Calculate ceil value for input """182 return 'ceil', attrs, inputs183def floor(attrs, inputs, proto_obj):184 """ Calculate floor value for input """185 return 'floor', attrs, inputs186# Joining and spliting187def concat(attrs, inputs, proto_obj):188 """ Joins input arrays along a given axis. """189 new_attrs = translation_utils._fix_attribute_names(attrs, {'axis': 'dim'})190 return 'concat', new_attrs, inputs191# Basic neural network functions192def softsign(attrs, inputs, proto_obj):193 """Computes softsign of x element-wise."""194 return 'softsign', attrs, inputs195def sigmoid(attrs, inputs, proto_obj):196 """Computes elementwise sigmoid of the input array"""197 return 'sigmoid', attrs, inputs198def hardsigmoid(attrs, inputs, proto_obj):199 """Computes elementwise hard sigmoid of the input array"""200 return 'hard_sigmoid', attrs, inputs201def relu(attrs, inputs, proto_obj):202 """Computes rectified linear function."""203 return 'relu', attrs, inputs204def pad(attrs, inputs, proto_obj):205 """ Add padding to input tensor"""206 new_attrs = translation_utils._fix_attribute_names(attrs, {'pads' : 'pad_width',207 'value' : 'constant_value'208 })209 new_attrs['pad_width'] = translation_utils._pad_sequence_fix(new_attrs.get('pad_width'))210 return 'pad', new_attrs, inputs211def matrix_multiplication(attrs, inputs, proto_obj):212 """Performs general matrix multiplication"""213 return 'linalg_gemm2', attrs, inputs214def batch_norm(attrs, inputs, proto_obj):215 """Batch normalization."""216 new_attrs = translation_utils._fix_attribute_names(attrs, {'epsilon': 'eps',217 'is_test': 'fix_gamma'})218 new_attrs = translation_utils._remove_attributes(new_attrs,219 ['spatial', 'consumed_inputs'])220 # Disable cuDNN BN only if epsilon from model is < than minimum cuDNN eps (1e-5)221 cudnn_min_eps = 1e-5222 cudnn_off = 0 if attrs.get('epsilon', cudnn_min_eps) >= cudnn_min_eps else 1223 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'cudnn_off': cudnn_off})224 # in test mode "fix_gamma" should be unset.225 new_attrs['fix_gamma'] = not attrs.get('is_test', 1)226 return 'BatchNorm', new_attrs, inputs227def instance_norm(attrs, inputs, proto_obj):228 """Instance Normalization."""229 new_attrs = translation_utils._fix_attribute_names(attrs, {'epsilon' : 'eps'})230 new_attrs['eps'] = attrs.get('epsilon', 1e-5)231 return 'InstanceNorm', new_attrs, inputs232def leaky_relu(attrs, inputs, proto_obj):233 """Leaky Relu function"""234 if 'alpha' in attrs:235 new_attrs = translation_utils._fix_attribute_names(attrs, {'alpha' : 'slope'})236 else:237 new_attrs = translation_utils._add_extra_attributes(attrs, {'slope': 0.01})238 return 'LeakyReLU', new_attrs, inputs239def _elu(attrs, inputs, proto_obj):240 """Elu function"""241 if 'alpha' in attrs:242 new_attrs = translation_utils._fix_attribute_names(attrs, {'alpha' : 'slope'})243 else:244 new_attrs = translation_utils._add_extra_attributes(attrs, {'slope': 1.0})245 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'act_type': 'elu'})246 return 'LeakyReLU', new_attrs, inputs247def _prelu(attrs, inputs, proto_obj):248 """PRelu function"""249 new_attrs = translation_utils._add_extra_attributes(attrs, {'act_type': 'prelu'})250 return 'LeakyReLU', new_attrs, inputs251def _selu(attrs, inputs, proto_obj):252 """Selu function"""253 new_attrs = translation_utils._add_extra_attributes(attrs, {'act_type': 'selu'})254 return 'LeakyReLU', new_attrs, inputs255def softmax(attrs, inputs, proto_obj):256 """Softmax function."""257 if 'axis' not in attrs:258 attrs = translation_utils._add_extra_attributes(attrs, {'axis': 1})259 return 'softmax', attrs, inputs260def log_softmax(attrs, inputs, proto_obj):261 """Computes the log softmax of the input. This is equivalent to262 computing softmax followed by log."""263 return 'log_softmax', attrs, inputs264def softplus(attrs, inputs, proto_obj):265 """Applies the sofplus activation function element-wise to the input."""266 new_attrs = translation_utils._add_extra_attributes(attrs, {'act_type' : 'softrelu'})267 return 'Activation', new_attrs, inputs268def conv(attrs, inputs, proto_obj):269 """Compute N-D convolution on (N+2)-D input."""270 new_attrs = translation_utils._fix_attribute_names(attrs, {'kernel_shape' : 'kernel',271 'strides' : 'stride',272 'pads': 'pad',273 'dilations': 'dilate',274 'group': 'num_group'})275 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'num_group' : 1})276 new_attrs = translation_utils._fix_bias('Convolution', new_attrs, len(inputs))277 new_attrs = translation_utils._fix_channels('Convolution', new_attrs, inputs, proto_obj)278 kernel = new_attrs['kernel']279 stride = new_attrs['stride'] if 'stride' in new_attrs else []280 padding = new_attrs['pad'] if 'pad' in new_attrs else []281 dilations = new_attrs['dilate'] if 'dilate' in new_attrs else []282 num_filter = new_attrs['num_filter']283 num_group = new_attrs['num_group']284 no_bias = new_attrs['no_bias'] if 'no_bias' in new_attrs else 0285 bias = None if no_bias is True else inputs[2]286 # Unlike ONNX, MXNet's convolution operator does not support asymmetric padding, so we first287 # use 'Pad' operator, which supports asymmetric padding. Then use the convolution operator.288 pad_width = (0, 0, 0, 0) + translation_utils._pad_sequence_fix(padding, kernel_dim=len(kernel))289 pad_op = symbol.pad(inputs[0], mode='constant', pad_width=pad_width)290 conv_op = symbol.Convolution(pad_op, inputs[1], bias,291 kernel=kernel, stride=stride, dilate=dilations,292 num_filter=num_filter, num_group=num_group, no_bias=no_bias)293 return conv_op, new_attrs, inputs294def deconv(attrs, inputs, proto_obj):295 """Computes transposed convolution of the input tensor."""296 new_attrs = translation_utils._fix_attribute_names(attrs, {'kernel_shape' : 'kernel',297 'strides' : 'stride',298 'pads': 'pad',299 'dilations': 'dilate',300 'group': 'num_group'})301 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'num_group' : 1})302 new_attrs = translation_utils._fix_bias('Deconvolution', new_attrs, len(inputs))303 new_attrs = translation_utils._fix_channels('Deconvolution', new_attrs, inputs, proto_obj)304 kernel = new_attrs['kernel']305 stride = new_attrs['stride'] if 'stride' in new_attrs else []306 padding = new_attrs['pad'] if 'pad' in new_attrs else []307 dilations = new_attrs['dilate'] if 'dilate' in new_attrs else []308 num_filter = new_attrs['num_filter']309 num_group = new_attrs['num_group']310 no_bias = new_attrs['no_bias'] if 'no_bias' in new_attrs else False311 bias = None if no_bias is True else inputs[2]312 # Unlike ONNX, MXNet's deconvolution operator does not support asymmetric padding, so we first313 # use 'Pad' operator, which supports asymmetric padding. Then use the deconvolution operator.314 pad_width = (0, 0, 0, 0) + translation_utils._pad_sequence_fix(padding, kernel_dim=len(kernel))315 pad_op = symbol.pad(inputs[0], mode='constant', pad_width=pad_width)316 deconv_op = symbol.Deconvolution(pad_op, inputs[1], bias,317 kernel=kernel, stride=stride, dilate=dilations,318 num_filter=num_filter, num_group=num_group, no_bias=no_bias)319 return deconv_op, new_attrs, inputs320def fully_connected(attrs, inputs, proto_obj):321 """Applies a linear transformation: Y=XWT+b."""322 new_attrs = translation_utils._remove_attributes(attrs, ['axis'])323 new_attrs = translation_utils._fix_bias('FullyConnected', new_attrs, len(inputs))324 new_attrs = translation_utils._fix_channels('FullyConnected', new_attrs, inputs, proto_obj)325 return 'FullyConnected', new_attrs, inputs326def global_maxpooling(attrs, inputs, proto_obj):327 """Performs max pooling on the input."""328 new_attrs = translation_utils._add_extra_attributes(attrs, {'global_pool': True,329 'kernel': (1, 1),330 'pool_type': 'max'})331 return 'Pooling', new_attrs, inputs332def global_avgpooling(attrs, inputs, proto_obj):333 """Performs avg pooling on the input."""334 new_attrs = translation_utils._add_extra_attributes(attrs, {'global_pool': True,335 'kernel': (1, 1),336 'pool_type': 'avg'})337 return 'Pooling', new_attrs, inputs338def global_lppooling(attrs, inputs, proto_obj):339 """Performs global lp pooling on the input."""340 p_value = attrs.get('p', 2)341 new_attrs = translation_utils._add_extra_attributes(attrs, {'global_pool': True,342 'kernel': (1, 1),343 'pool_type': 'lp',344 'p_value': p_value})345 new_attrs = translation_utils._remove_attributes(new_attrs, ['p'])346 return 'Pooling', new_attrs, inputs347def linalg_gemm(attrs, inputs, proto_obj):348 """Performs general matrix multiplication and accumulation"""349 trans_a = 0350 trans_b = 0351 alpha = 1352 beta = 1353 if 'transA' in attrs:354 trans_a = attrs['transA']355 if 'transB' in attrs:356 trans_b = attrs['transB']357 if 'alpha' in attrs:358 alpha = attrs['alpha']359 if 'beta' in attrs:360 beta = attrs['beta']361 flatten_a = symbol.flatten(inputs[0])362 matmul_op = symbol.linalg_gemm2(A=flatten_a, B=inputs[1],363 transpose_a=trans_a, transpose_b=trans_b,364 alpha=alpha)365 gemm_op = symbol.broadcast_add(matmul_op, beta*inputs[2])366 new_attrs = translation_utils._fix_attribute_names(attrs, {'transA': 'transpose_a',367 'transB': 'transpose_b'})368 new_attrs = translation_utils._remove_attributes(new_attrs, ['broadcast'])369 return gemm_op, new_attrs, inputs370def local_response_norm(attrs, inputs, proto_obj):371 """Local Response Normalization."""372 new_attrs = translation_utils._fix_attribute_names(attrs,373 {'bias': 'knorm',374 'size' : 'nsize'})375 return 'LRN', new_attrs, inputs376def dropout(attrs, inputs, proto_obj):377 """Dropout Regularization."""378 mode = 'training'379 if 'is_test' in attrs and attrs['is_test'] == 0:380 mode = 'always'381 new_attrs = translation_utils._fix_attribute_names(attrs,382 {'ratio': 'p'})383 new_attrs = translation_utils._remove_attributes(new_attrs, ['is_test'])384 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'mode': mode})385 return 'Dropout', new_attrs, inputs386# Changing shape and type.387def reshape(attrs, inputs, proto_obj):388 """Reshape the given array by the shape attribute."""389 if len(inputs) == 1:390 return 'reshape', attrs, inputs[0]391 reshape_shape = list(proto_obj._params[inputs[1].name].asnumpy())392 reshape_shape = [int(i) for i in reshape_shape]393 new_attrs = {'shape': reshape_shape}394 return 'reshape', new_attrs, inputs[:1]395def cast(attrs, inputs, proto_obj):396 """ Cast input to a given dtype"""397 try:398 from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE399 except ImportError:400 raise ImportError("Onnx and protobuf need to be installed. "401 + "Instructions to install - https://github.com/onnx/onnx")402 new_attrs = translation_utils._fix_attribute_names(attrs, {'to' : 'dtype'})403 new_attrs['dtype'] = TENSOR_TYPE_TO_NP_TYPE[int(new_attrs['dtype'])]404 return 'cast', new_attrs, inputs405def split(attrs, inputs, proto_obj):406 """Splits an array along a particular axis into multiple sub-arrays."""407 split_list = attrs.get('split') if 'split' in attrs else []408 new_attrs = translation_utils._fix_attribute_names(attrs,409 {'split' : 'num_outputs'})410 if 'axis' not in attrs:411 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'axis': 0})412 if not split_list:413 num_outputs = len(proto_obj.model_metadata.get('output_tensor_data'))414 else:415 if len(set(split_list)) == 1:416 num_outputs = len(split_list)417 else:418 raise NotImplementedError("Operator {} in MXNet does not support variable splits."419 "Tracking the issue to support variable split here: "420 "https://github.com/apache/incubator-mxnet/issues/11594"421 .format('split'))422 new_attrs['num_outputs'] = num_outputs423 return 'split', new_attrs, inputs424def _slice(attrs, inputs, proto_obj):425 """Returns a slice of the input tensor along multiple axes."""426 new_attrs = translation_utils._fix_attribute_names(attrs,427 {'axes' : 'axis',428 'ends' : 'end',429 'starts' : 'begin'})430 # onnx slice provides slicing on multiple axis. Adding multiple slice_axis operator431 # for multiple axes from mxnet432 begin = new_attrs.get('begin')433 end = new_attrs.get('end')434 axes = new_attrs.get('axis', tuple(range(len(begin))))435 slice_op = symbol.slice_axis(inputs[0], axis=axes[0], begin=begin[0], end=end[0])436 if len(axes) > 1:437 for i, axis in enumerate(axes):438 slice_op = symbol.slice_axis(slice_op, axis=axis, begin=begin[i], end=end[i])439 return slice_op, new_attrs, inputs440def transpose(attrs, inputs, proto_obj):441 """Transpose the input array."""442 new_attrs = translation_utils._fix_attribute_names(attrs,443 {'perm' : 'axes'})444 return 'transpose', new_attrs, inputs445def squeeze(attrs, inputs, proto_obj):446 """Remove single-dimensional entries from the shape of a tensor."""447 new_attrs = translation_utils._fix_attribute_names(attrs,448 {'axes' : 'axis'})449 return 'squeeze', new_attrs, inputs450def unsqueeze(attrs, inputs, cls):451 """Inserts a new axis of size 1 into the array shape"""452 # MXNet can only add one axis at a time.453 mxnet_op = inputs[0]454 for axis in attrs["axes"]:455 mxnet_op = symbol.expand_dims(mxnet_op, axis=axis)456 return mxnet_op, attrs, inputs457def flatten(attrs, inputs, proto_obj):458 """Flattens the input array into a 2-D array by collapsing the higher dimensions."""459 #Mxnet does not have axis support. By default uses axis=1460 if 'axis' in attrs and attrs['axis'] != 1:461 raise RuntimeError("Flatten operator only supports axis=1")462 new_attrs = translation_utils._remove_attributes(attrs, ['axis'])463 return 'Flatten', new_attrs, inputs464def clip(attrs, inputs, proto_obj):465 """Clips (limits) the values in an array."""466 new_attrs = translation_utils._fix_attribute_names(attrs, {'min' : 'a_min',467 'max' : 'a_max'})468 if 'a_max' not in new_attrs:469 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'a_max' : np.inf})470 if 'a_min' not in new_attrs:471 new_attrs = translation_utils._add_extra_attributes(new_attrs, {'a_min' : -np.inf})472 return 'clip', new_attrs, inputs473def gather(attrs, inputs, proto_obj):474 """Gather elements from an input array along the given axis."""475 return 'take', attrs, inputs476#Powers477def reciprocal(attrs, inputs, proto_obj):478 """Returns the reciprocal of the argument, element-wise."""479 return 'reciprocal', attrs, inputs480def squareroot(attrs, inputs, proto_obj):481 """Returns element-wise square-root value of the input."""482 return 'sqrt', attrs, inputs483def power(attrs, inputs, proto_obj):484 """Returns element-wise result of base element raised to powers from exp element."""485 new_attrs = translation_utils._fix_attribute_names(attrs, {'exponent':'exp'})486 if 'broadcast' in attrs:487 new_attrs = translation_utils._remove_attributes(new_attrs, ['broadcast'])488 if attrs['broadcast'] == 1:489 return 'broadcast_power', new_attrs, inputs490 else:491 mxnet_op = symbol.pow(inputs[0], inputs[1])492 return mxnet_op, new_attrs, inputs493 mxnet_op = symbol.broadcast_power(inputs[0], inputs[1])494 return mxnet_op, new_attrs, inputs495def exponent(attrs, inputs, proto_obj):496 """Elementwise exponent of input array."""497 return 'exp', attrs, inputs498def _cos(attrs, inputs, proto_obj):499 """Elementwise cosine of input array."""500 return 'cos', attrs, inputs501def _sin(attrs, inputs, proto_obj):502 """Elementwise sine of input array."""503 return 'sin', attrs, inputs504def _tan(attrs, inputs, proto_obj):505 """Elementwise tan of input array."""506 return 'tan', attrs, inputs507def arccos(attrs, inputs, proto_obj):508 """Elementwise inverse cos of input array."""509 return 'arccos', attrs, inputs510def arcsin(attrs, inputs, proto_obj):511 """Elementwise inverse sin of input array."""512 return 'arcsin', attrs, inputs513def arctan(attrs, inputs, proto_obj):514 """Elementwise inverse tan of input array."""515 return 'arctan', attrs, inputs516def _log(attrs, inputs, proto_obj):517 """Elementwise log of input array."""518 return 'log', attrs, inputs519# Reduce Functions520def reduce_max(attrs, inputs, proto_obj):521 """Reduce the array along a given axis by maximum value"""522 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})523 return 'max', new_attrs, inputs524def reduce_mean(attrs, inputs, proto_obj):525 """Reduce the array along a given axis by mean value"""526 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})527 return 'mean', new_attrs, inputs528def reduce_min(attrs, inputs, proto_obj):529 """Reduce the array along a given axis by minimum value"""530 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})531 return 'min', new_attrs, inputs532def reduce_sum(attrs, inputs, proto_obj):533 """Reduce the array along a given axis by sum value"""534 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})535 return 'sum', new_attrs, inputs536def reduce_prod(attrs, inputs, proto_obj):537 """Reduce the array along a given axis by product value"""538 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})539 return 'prod', new_attrs, inputs540def reduce_log_sum(attrs, inputs, proto_obj):541 """Reduce the array along a given axis by log sum value"""542 keep_dims = True if 'keepdims' not in attrs else attrs.get('keepdims')543 sum_op = symbol.sum(inputs[0], axis=attrs.get('axes'),544 keepdims=keep_dims)545 log_sym = symbol.log(sum_op)546 return log_sym, attrs, inputs547def reduce_log_sum_exp(attrs, inputs, proto_obj):548 """Reduce the array along a given axis by log sum exp value"""549 keep_dims = True if 'keepdims' not in attrs else attrs.get('keepdims')550 exp_op = symbol.exp(inputs[0])551 sum_op = symbol.sum(exp_op, axis=attrs.get('axes'),552 keepdims=keep_dims)553 log_sym = symbol.log(sum_op)554 return log_sym, attrs, inputs555def reduce_sum_square(attrs, inputs, proto_obj):556 """Reduce the array along a given axis by sum square value"""557 square_op = symbol.square(inputs[0])558 sum_op = symbol.sum(square_op, axis=attrs.get('axes'),559 keepdims=attrs.get('keepdims'))560 return sum_op, attrs, inputs561def reduce_l1(attrs, inputs, proto_obj):562 """Reduce input tensor by l1 normalization."""563 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})564 new_attrs = translation_utils._add_extra_attributes(new_attrs,565 {'ord' : 1})566 return 'norm', new_attrs, inputs567def shape(attrs, inputs, proto_obj):568 """Returns shape of input array."""569 return 'shape_array', attrs, inputs570def size(attrs, inputs, proto_obj):571 """Returns array containing size of data."""572 return "size_array", attrs, inputs573def reduce_l2(attrs, inputs, proto_obj):574 """Reduce input tensor by l2 normalization."""575 new_attrs = translation_utils._fix_attribute_names(attrs, {'axes':'axis'})576 return 'norm', new_attrs, inputs577def avg_pooling(attrs, inputs, proto_obj):578 """ Average pooling"""579 new_attrs = translation_utils._fix_attribute_names(attrs,580 {'kernel_shape': 'kernel',581 'strides': 'stride',582 'pads': 'pad',583 })584 new_attrs = translation_utils._add_extra_attributes(new_attrs,585 {'pooling_convention': 'valid'586 })587 new_op = translation_utils._fix_pooling('avg', inputs, new_attrs)588 return new_op, new_attrs, inputs589def lp_pooling(attrs, inputs, proto_obj):590 """LP Pooling"""591 p_value = attrs.get('p', 2)592 new_attrs = translation_utils._fix_attribute_names(attrs,593 {'kernel_shape': 'kernel',594 'strides': 'stride',595 'pads': 'pad'596 })597 new_attrs = translation_utils._remove_attributes(new_attrs, ['p'])598 new_attrs = translation_utils._add_extra_attributes(new_attrs,599 {'pooling_convention': 'valid',600 'p_value': p_value601 })602 new_op = translation_utils._fix_pooling('lp', inputs, new_attrs)603 return new_op, new_attrs, inputs604def max_pooling(attrs, inputs, proto_obj):605 """ Average pooling"""606 new_attrs = translation_utils._fix_attribute_names(attrs,607 {'kernel_shape': 'kernel',608 'strides': 'stride',609 'pads': 'pad',610 })611 new_attrs = translation_utils._add_extra_attributes(new_attrs,612 {'pooling_convention': 'valid'613 })614 new_op = translation_utils._fix_pooling('max', inputs, new_attrs)615 return new_op, new_attrs, inputs616def max_roi_pooling(attrs, inputs, proto_obj):617 """Max ROI Pooling."""618 new_attrs = translation_utils._fix_attribute_names(attrs,619 {'pooled_shape': 'pooled_size',620 'spatial_scale': 'spatial_scale'621 })622 return 'ROIPooling', new_attrs, inputs623def depthtospace(attrs, inputs, proto_obj):624 """Rearranges data from depth into blocks of spatial data."""625 new_attrs = translation_utils._fix_attribute_names(attrs, {'blocksize':'block_size'})626 return "depth_to_space", new_attrs, inputs627def spacetodepth(attrs, inputs, proto_obj):628 """Rearranges blocks of spatial data into depth."""629 new_attrs = translation_utils._fix_attribute_names(attrs, {'blocksize':'block_size'})630 return "space_to_depth", new_attrs, inputs631def hardmax(attrs, inputs, proto_obj):632 """Returns batched one-hot vectors."""633 input_tensor_data = proto_obj.model_metadata.get('input_tensor_data')[0]634 input_shape = input_tensor_data[1]635 axis = int(attrs.get('axis', 1))636 axis = axis if axis >= 0 else len(input_shape) + axis637 if axis == len(input_shape) - 1:638 amax = symbol.argmax(inputs[0], axis=-1)639 one_hot = symbol.one_hot(amax, depth=input_shape[-1])640 return one_hot, attrs, inputs641 # since reshape doesn't take a tensor for shape,642 # computing with np.prod. This needs to be changed to643 # to use mx.sym.prod() when mx.sym.reshape() is fixed.644 # (https://github.com/apache/incubator-mxnet/issues/10789)645 new_shape = (int(np.prod(input_shape[:axis])),646 int(np.prod(input_shape[axis:])))647 reshape_op = symbol.reshape(inputs[0], new_shape)648 amax = symbol.argmax(reshape_op, axis=-1)649 one_hot = symbol.one_hot(amax, depth=new_shape[-1])650 hardmax_op = symbol.reshape(one_hot, input_shape)651 return hardmax_op, attrs, inputs652def lpnormalization(attrs, inputs, proto_obj):653 """ONNX does not have eps attribute, so cannot map it to L2normalization in MXNet654 without that, it works as norm operator discussion in PR:655 https://github.com/onnx/onnx/pull/1330"""656 new_attrs = translation_utils._fix_attribute_names(attrs, {'p': 'ord'})657 axis = int(attrs.get("axis", -1))658 new_attrs.update(axis=axis)659 return 'norm', new_attrs, inputs660def topk(attrs, inputs, proto_obj):661 """Returns the top k elements in an input array along the given axis."""662 new_attrs = translation_utils._add_extra_attributes(attrs,663 {'ret_typ': 'both',664 'dtype': 'int64'})...

Full Screen

Full Screen

filtereventhandler.py

Source:filtereventhandler.py Github

copy

Full Screen

...122 removed_attrs = {}123 if isinstance(event, core_events.PortEvent):124 port = event.get_port()125 old_attrs = self._port_attrs.get(port.get_id(), {})126 new_attrs = await port.get_attrs()127 old_value = self._port_values.get(port.get_id())128 new_value = port.get_last_read_value()129 value_pair = (old_value, new_value)130 if isinstance(event, (core_events.PortAdd, core_events.PortUpdate)):131 changed_attrs, added_attrs, removed_attrs = self._make_changed_added_removed(old_attrs, new_attrs)132 self._port_values[port.get_id()] = new_value133 self._port_attrs[port.get_id()] = new_attrs134 elif isinstance(event, core_events.PortRemove):135 self._port_values.pop(port.get_id(), None)136 removed_attrs = self._port_attrs.pop(port.get_id(), {})137 elif isinstance(event, core_events.ValueChange):138 self._port_values[port.get_id()] = new_value139 elif isinstance(event, core_events.DeviceEvent):140 old_attrs = self._device_attrs141 new_attrs = event.get_attrs()142 changed_attrs, added_attrs, removed_attrs = self._make_changed_added_removed(old_attrs, new_attrs)143 self._device_attrs = new_attrs144 elif isinstance(event, slaves_events.SlaveDeviceEvent):145 slave = event.get_slave()146 slave_json = slave.to_json()147 # Flatten slave master properties and attributes148 old_attrs = self._slave_attrs.get(slave.get_name(), {})149 new_attrs = dict(slave_json, **slave_json.pop('attrs'))150 if isinstance(event, (slaves_events.SlaveDeviceAdd, slaves_events.SlaveDeviceUpdate)):151 changed_attrs, added_attrs, removed_attrs = self._make_changed_added_removed(old_attrs, new_attrs)152 self._slave_attrs[slave.get_name()] = new_attrs153 elif isinstance(event, slaves_events.SlaveDeviceRemove):154 removed_attrs = self._slave_attrs.pop(slave.get_name(), {})155 return value_pair, old_attrs, new_attrs, changed_attrs, added_attrs, removed_attrs156 @staticmethod157 def _accepts_attrs(158 attr_names: Set[str],159 filter_attrs: Attributes,160 filter_attr_transitions: Dict[str, Tuple[Attribute, Attribute]],161 old_attrs: Attributes,162 new_attrs: Attributes163 ) -> bool:164 for name in attr_names:165 old_value = old_attrs.get(name)166 new_value = new_attrs.get(name)167 filter_transition = filter_attr_transitions.get(name)168 if filter_transition is not None:169 old_filter_value, new_filter_value = filter_transition170 if ((old_filter_value != old_value and old_filter_value is not None) or171 (new_filter_value != new_value and new_filter_value is not None)):172 return False173 filter_value = filter_attrs.get(name)174 if filter_value is not None:175 if isinstance(filter_value, list): # A list of accepted values176 if new_value not in filter_value:177 return False178 elif new_value != filter_value: # A single value179 return False180 return True181 async def accepts_device(self, event: core_events.Event, old_attrs: Attributes, new_attrs: Attributes) -> bool:182 return self._accepts_attrs(183 self._filter_device_attr_names,184 self._filter_device_attrs,185 self._filter_device_attr_transitions,186 old_attrs,187 new_attrs188 )189 async def accepts_port_value(190 self,191 event: core_events.Event,192 value_pair: Tuple[NullablePortValue, NullablePortValue]193 ) -> bool:194 old_value, new_value = value_pair195 if self._filter_port_value_transition is not None:196 old_filter_value, new_filter_value = self._filter_port_value_transition197 if ((old_filter_value != old_value and old_filter_value is not None) or198 (new_filter_value != new_value and new_filter_value is not None)):199 return False200 if self._filter_port_value is not None:201 if isinstance(self._filter_port_value, list): # A list of accepted values202 if new_value not in self._filter_port_value:203 return False204 elif isinstance(self._filter_port_value, core_expressions.Expression): # An expression205 if new_value != await self._filter_port_value.eval(context={}):206 return False207 return True208 async def accepts_port(209 self,210 event: core_events.Event,211 value_pair: Tuple[NullablePortValue, NullablePortValue],212 old_attrs: Attributes,213 new_attrs: Attributes214 ) -> bool:215 if not await self.accepts_port_value(event, value_pair):216 return False217 return self._accepts_attrs(218 self._filter_port_attr_names,219 self._filter_port_attrs,220 self._filter_port_attr_transitions,221 old_attrs,222 new_attrs223 )224 async def accepts_slave(self, event: core_events.Event, old_attrs: Attributes, new_attrs: Attributes) -> bool:225 return self._accepts_attrs(226 self._filter_slave_attr_names,227 self._filter_slave_attrs,228 self._filter_slave_attr_transitions,229 old_attrs,230 new_attrs231 )232 async def accepts(233 self,234 event: core_events.Event,235 value_pair: Tuple[NullablePortValue, NullablePortValue],236 old_attrs: Attributes,237 new_attrs: Attributes,238 changed_attrs: Dict[str, Tuple[Attribute, Attribute]],239 added_attrs: Attributes,...

Full Screen

Full Screen

nvD3AxisConfiguration.js

Source:nvD3AxisConfiguration.js Github

copy

Full Screen

1function configureXaxis(chart, scope, attrs) {2 if (attrs.xaxisorient) {3 chart.xAxis.orient(attrs.xaxisorient);4 }5 if (attrs.xaxisticks) {6 chart.xAxis.scale().ticks(attrs.xaxisticks);7 }8 if (attrs.xaxistickvalues) {9 if (Array.isArray(scope.$eval(attrs.xaxistickvalues))) {10 chart.xAxis.tickValues(scope.$eval(attrs.xaxistickvalues));11 } else if (typeof scope.xaxistickvalues() === 'function') {12 chart.xAxis.tickValues(scope.xaxistickvalues());13 }14 }15 if (attrs.xaxisticksubdivide) {16 chart.xAxis.tickSubdivide(scope.xaxisticksubdivide());17 }18 if (attrs.xaxisticksize) {19 chart.xAxis.tickSize(scope.xaxisticksize());20 }21 if (attrs.xaxistickpadding) {22 chart.xAxis.tickPadding(scope.xaxistickpadding());23 }24 if (attrs.xaxistickformat) {25 chart.xAxis.tickFormat(scope.xaxistickformat());26 }27 if (attrs.xaxislabel) {28 chart.xAxis.axisLabel(attrs.xaxislabel);29 }30 if (attrs.xaxisscale) {31 chart.xAxis.scale(scope.xaxisscale());32 }33 if (attrs.xaxisdomain) {34 if (Array.isArray(scope.$eval(attrs.xaxisdomain))) {35 chart.xDomain(scope.$eval(attrs.xaxisdomain));36 } else if (typeof scope.xaxisdomain() === 'function') {37 chart.xDomain(scope.xaxisdomain());38 }39 }40 if (attrs.xaxisrange) {41 if (Array.isArray(scope.$eval(attrs.xaxisrange))) {42 chart.xRange(scope.$eval(attrs.xaxisrange));43 } else if (typeof scope.xaxisrange() === 'function') {44 chart.xRange(scope.xaxisrange());45 }46 }47 if (attrs.xaxisrangeband) {48 chart.xAxis.rangeBand(scope.xaxisrangeband());49 }50 if (attrs.xaxisrangebands) {51 chart.xAxis.rangeBands(scope.xaxisrangebands());52 }53 if (attrs.xaxisshowmaxmin) {54 chart.xAxis.showMaxMin((attrs.xaxisshowmaxmin === 'true'));55 }56 if (attrs.xaxishighlightzero) {57 chart.xAxis.highlightZero((attrs.xaxishighlightzero === 'true'));58 }59 if (attrs.xaxisrotatelabels) {60 chart.xAxis.rotateLabels((+attrs.xaxisrotatelabels));61 }62 // if(attrs.xaxisrotateylabel){63 // chart.xAxis.rotateYLabel((attrs.xaxisrotateylabel === "true"));64 // }65 if (attrs.xaxisstaggerlabels) {66 chart.xAxis.staggerLabels((attrs.xaxisstaggerlabels === 'true'));67 }68 if (attrs.xaxislabeldistance) {69 chart.xAxis.axisLabelDistance((+attrs.xaxislabeldistance));70 }71}72function configureX2axis (chart, scope, attrs) {73 if (attrs.x2axisorient) {74 chart.x2Axis.orient(attrs.x2axisorient);75 }76 if (attrs.x2axisticks) {77 chart.x2Axis.scale().ticks(attrs.x2axisticks);78 }79 if (attrs.x2axistickvalues) {80 if (Array.isArray(scope.$eval(attrs.x2axistickvalues))) {81 chart.x2Axis.tickValues(scope.$eval(attrs.x2axistickvalues));82 } else if (typeof scope.xaxistickvalues() === 'function') {83 chart.x2Axis.tickValues(scope.x2axistickvalues());84 }85 }86 if (attrs.x2axisticksubdivide) {87 chart.x2Axis.tickSubdivide(scope.x2axisticksubdivide());88 }89 if (attrs.x2axisticksize) {90 chart.x2Axis.tickSize(scope.x2axisticksize());91 }92 if (attrs.x2axistickpadding) {93 chart.x2Axis.tickPadding(scope.x2axistickpadding());94 }95 if (attrs.x2axistickformat) {96 chart.x2Axis.tickFormat(scope.x2axistickformat());97 }98 if (attrs.x2axislabel) {99 chart.x2Axis.axisLabel(attrs.x2axislabel);100 }101 if (attrs.x2axisscale) {102 chart.x2Axis.scale(scope.x2axisscale());103 }104 if (attrs.x2axisdomain) {105 if (Array.isArray(scope.$eval(attrs.x2axisdomain))) {106 chart.x2Axis.domain(scope.$eval(attrs.x2axisdomain));107 } else if (typeof scope.x2axisdomain() === 'function') {108 chart.x2Axis.domain(scope.x2axisdomain());109 }110 }111 if (attrs.x2axisrange) {112 if (Array.isArray(scope.$eval(attrs.x2axisrange))) {113 chart.x2Axis.range(scope.$eval(attrs.x2axisrange));114 } else if (typeof scope.x2axisrange() === 'function') {115 chart.x2Axis.range(scope.x2axisrange());116 }117 }118 if (attrs.x2axisrangeband) {119 chart.x2Axis.rangeBand(scope.x2axisrangeband());120 }121 if (attrs.x2axisrangebands) {122 chart.x2Axis.rangeBands(scope.x2axisrangebands());123 }124 if (attrs.x2axisshowmaxmin) {125 chart.x2Axis.showMaxMin((attrs.x2axisshowmaxmin === 'true'));126 }127 if (attrs.x2axishighlightzero) {128 chart.x2Axis.highlightZero((attrs.x2axishighlightzero === 'true'));129 }130 if (attrs.x2axisrotatelables) {131 chart.x2Axis.rotateLabels((+attrs.x2axisrotatelables));132 }133 // if(attrs.xaxisrotateylabel){134 // chart.xAxis.rotateYLabel((attrs.xaxisrotateylabel === "true"));135 // }136 if (attrs.x2axisstaggerlabels) {137 chart.x2Axis.staggerLabels((attrs.x2axisstaggerlabels === 'true'));138 }139 if (attrs.x2axislabeldistance) {140 chart.x2Axis.axisLabelDistance((+attrs.x2axislabeldistance));141 }142}143function configureYaxis (chart, scope, attrs) {144 if (attrs.yaxisorient) {145 chart.yAxis.orient(attrs.yaxisorient);146 }147 if (attrs.yaxisticks) {148 chart.yAxis.scale().ticks(attrs.yaxisticks);149 }150 if (attrs.yaxistickvalues) {151 if (Array.isArray(scope.$eval(attrs.yaxistickvalues))) {152 chart.yAxis.tickValues(scope.$eval(attrs.yaxistickvalues));153 } else if (typeof scope.yaxistickvalues() === 'function') {154 chart.yAxis.tickValues(scope.yaxistickvalues());155 }156 }157 if (attrs.yaxisticksubdivide) {158 chart.yAxis.tickSubdivide(scope.yaxisticksubdivide());159 }160 if (attrs.yaxisticksize) {161 chart.yAxis.tickSize(scope.yaxisticksize());162 }163 if (attrs.yaxistickpadding) {164 chart.yAxis.tickPadding(scope.yaxistickpadding());165 }166 if (attrs.yaxistickformat) {167 chart.yAxis.tickFormat(scope.yaxistickformat());168 }169 if (attrs.yaxislabel) {170 chart.yAxis.axisLabel(attrs.yaxislabel);171 }172 if (attrs.yaxisscale) {173 chart.yAxis.scale(scope.yaxisscale());174 }175 if (attrs.yaxisdomain) {176 if (Array.isArray(scope.$eval(attrs.yaxisdomain))) {177 chart.yDomain(scope.$eval(attrs.yaxisdomain));178 } else if (typeof scope.yaxisdomain() === 'function') {179 chart.yDomain(scope.yaxisdomain());180 }181 }182 if (attrs.yaxisrange) {183 if (Array.isArray(scope.$eval(attrs.yaxisrange))) {184 chart.yRange(scope.$eval(attrs.yaxisrange));185 } else if (typeof scope.yaxisrange() === 'function') {186 chart.yRange(scope.yaxisrange());187 }188 }189 if (attrs.yaxisrangeband) {190 chart.yAxis.rangeBand(scope.yaxisrangeband());191 }192 if (attrs.yaxisrangebands) {193 chart.yAxis.rangeBands(scope.yaxisrangebands());194 }195 if (attrs.yaxisshowmaxmin) {196 chart.yAxis.showMaxMin((attrs.yaxisshowmaxmin === 'true'));197 }198 if (attrs.yaxishighlightzero) {199 chart.yAxis.highlightZero((attrs.yaxishighlightzero === 'true'));200 }201 if (attrs.yaxisrotatelabels) {202 chart.yAxis.rotateLabels((+attrs.yaxisrotatelabels));203 }204 if (attrs.yaxisrotateylabel) {205 chart.yAxis.rotateYLabel((attrs.yaxisrotateylabel === 'true'));206 }207 if (attrs.yaxisstaggerlabels) {208 chart.yAxis.staggerLabels((attrs.yaxisstaggerlabels === 'true'));209 }210 if (attrs.yaxislabeldistance) {211 chart.yAxis.axisLabelDistance((+attrs.yaxislabeldistance));212 }213}214function configureY1axis (chart, scope, attrs) {215 if (attrs.y1axisticks) {216 chart.y1Axis.scale().ticks(attrs.y1axisticks);217 }218 if (attrs.y1axistickvalues) {219 if (Array.isArray(scope.$eval(attrs.y1axistickvalues))) {220 chart.y1Axis.tickValues(scope.$eval(attrs.y1axistickvalues));221 } else if (typeof scope.y1axistickvalues() === 'function') {222 chart.y1Axis.tickValues(scope.y1axistickvalues());223 }224 }225 if (attrs.y1axisticksubdivide) {226 chart.y1Axis.tickSubdivide(scope.y1axisticksubdivide());227 }228 if (attrs.y1axisticksize) {229 chart.y1Axis.tickSize(scope.y1axisticksize());230 }231 if (attrs.y1axistickpadding) {232 chart.y1Axis.tickPadding(scope.y1axistickpadding());233 }234 if (attrs.y1axistickformat) {235 chart.y1Axis.tickFormat(scope.y1axistickformat());236 }237 if (attrs.y1axislabel) {238 chart.y1Axis.axisLabel(attrs.y1axislabel);239 }240 if (attrs.y1axisscale) {241 chart.y1Axis.yScale(scope.y1axisscale());242 }243 if (attrs.y1axisdomain) {244 if (Array.isArray(scope.$eval(attrs.y1axisdomain))) {245 chart.y1Axis.domain(scope.$eval(attrs.y1axisdomain));246 } else if (typeof scope.y1axisdomain() === 'function') {247 chart.y1Axis.domain(scope.y1axisdomain());248 }249 }250 if (attrs.y1axisrange) {251 if (Array.isArray(scope.$eval(attrs.y1axisrange))) {252 chart.y1Axis.range(scope.$eval(attrs.y1axisrange));253 } else if (typeof scope.y1axisrange() === 'function') {254 chart.y1Axis.range(scope.y1axisrange());255 }256 }257 if (attrs.y1axisrangeband) {258 chart.y1Axis.rangeBand(scope.y1axisrangeband());259 }260 if (attrs.y1axisrangebands) {261 chart.y1Axis.rangeBands(scope.y1axisrangebands());262 }263 if (attrs.y1axisshowmaxmin) {264 chart.y1Axis.showMaxMin((attrs.y1axisshowmaxmin === 'true'));265 }266 if (attrs.y1axishighlightzero) {267 chart.y1Axis.highlightZero((attrs.y1axishighlightzero === 'true'));268 }269 if (attrs.y1axisrotatelabels) {270 chart.y1Axis.rotateLabels((+scope.y1axisrotatelabels));271 }272 if (attrs.y1axisrotateylabel) {273 chart.y1Axis.rotateYLabel((attrs.y1axisrotateylabel === 'true'));274 }275 if (attrs.y1axisstaggerlabels) {276 chart.y1Axis.staggerlabels((attrs.y1axisstaggerlabels === 'true'));277 }278 if (attrs.y1axislabeldistance) {279 chart.y1Axis.axisLabelDistance((+attrs.y1axislabeldistance));280 }281}282function configureY2axis (chart, scope, attrs) {283 if (attrs.y2axisticks) {284 chart.y2Axis.scale().ticks(attrs.y2axisticks);285 }286 if (attrs.y2axistickvalues) {287 chart.y2Axis.tickValues(scope.$eval(attrs.y2axistickvalues));288 }289 if (attrs.y2axisticksubdivide) {290 chart.y2Axis.tickSubdivide(scope.y2axisticksubdivide());291 }292 if (attrs.y2axisticksize) {293 chart.y2Axis.tickSize(scope.y2axisticksize());294 }295 if (attrs.y2axistickpadding) {296 chart.y2Axis.tickPadding(scope.y2axistickpadding());297 }298 if (attrs.y2axistickformat) {299 chart.y2Axis.tickFormat(scope.y2axistickformat());300 }301 if (attrs.y2axislabel) {302 chart.y2Axis.axisLabel(attrs.y2axislabel);303 }304 if (attrs.y2axisscale) {305 chart.y2Axis.yScale(scope.y2axisscale());306 }307 if (attrs.y2axisdomain) {308 if (Array.isArray(scope.$eval(attrs.y2axisdomain))) {309 chart.y2Axis.domain(scope.$eval(attrs.y2axisdomain));310 } else if (typeof scope.y2axisdomain() === 'function') {311 chart.y2Axis.domain(scope.y2axisdomain());312 }313 }314 if (attrs.y2axisrange) {315 if (Array.isArray(scope.$eval(attrs.y2axisrange))) {316 chart.y2Axis.range(scope.$eval(attrs.y2axisrange));317 } else if (typeof scope.y2axisrange() === 'function') {318 chart.y2Axis.range(scope.y2axisrange());319 }320 }321 if (attrs.y2axisrangeband) {322 chart.y2Axis.rangeBand(scope.y2axisrangeband());323 }324 if (attrs.y2axisrangebands) {325 chart.y2Axis.rangeBands(scope.y2axisrangebands());326 }327 if (attrs.y2axisshowmaxmin) {328 chart.y2Axis.showMaxMin((attrs.y2axisshowmaxmin === 'true'));329 }330 if (attrs.y2axishighlightzero) {331 chart.y2Axis.highlightZero((attrs.y2axishighlightzero === 'true'));332 }333 if (attrs.y2axisrotatelabels) {334 chart.y2Axis.rotateLabels((+scope.y2axisrotatelabels));335 }336 if (attrs.y2axisrotateylabel) {337 chart.y2Axis.rotateYLabel((attrs.y2axisrotateylabel === 'true'));338 }339 if (attrs.y2axisstaggerlabels) {340 chart.y2Axis.staggerlabels((attrs.y2axisstaggerlabels === 'true'));341 }342 if (attrs.y2axislabeldistance) {343 chart.y2Axis.axisLabelDistance((+attrs.y2axislabeldistance));344 }...

Full Screen

Full Screen

widgets.py

Source:widgets.py Github

copy

Full Screen

...97 if value is None:98 value = []99 has_id = attrs and 'id' in attrs100 if DJANGO_11:101 final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})102 else:103 final_attrs = self.build_attrs(attrs, name=name)104 output = []105 # Normalize to strings106 str_values = set([force_text(v) for v in value])107 for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):108 # If an ID attribute was given, add a numeric index as a suffix,109 # so that the checkboxes don't all have the same ID attribute.110 if has_id:111 final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))112 label_for = u' for="%s"' % final_attrs['id']113 else:114 label_for = ''115 cb = forms.CheckboxInput(116 final_attrs, check_test=lambda value: value in str_values)117 option_value = force_text(option_value)...

Full Screen

Full Screen

ssrVModel.spec.ts

Source:ssrVModel.spec.ts Github

copy

Full Screen

1import { compile } from '../src'2function compileWithWrapper(src: string) {3 return compile(`<div>${src}</div>`)4}5describe('ssr: v-model', () => {6 test('<input> (text types)', () => {7 expect(compileWithWrapper(`<input v-model="bar">`).code)8 .toMatchInlineSnapshot(`9 "const { ssrRenderAttr: _ssrRenderAttr, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")10 return function ssrRender(_ctx, _push, _parent, _attrs) {11 _push(\`<div\${12 _ssrRenderAttrs(_attrs)13 }><input\${14 _ssrRenderAttr(\\"value\\", _ctx.bar)15 }></div>\`)16 }"17 `)18 expect(compileWithWrapper(`<input type="email" v-model="bar">`).code)19 .toMatchInlineSnapshot(`20 "const { ssrRenderAttr: _ssrRenderAttr, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")21 return function ssrRender(_ctx, _push, _parent, _attrs) {22 _push(\`<div\${23 _ssrRenderAttrs(_attrs)24 }><input type=\\"email\\"\${25 _ssrRenderAttr(\\"value\\", _ctx.bar)26 }></div>\`)27 }"28 `)29 })30 test('<input type="radio">', () => {31 expect(32 compileWithWrapper(`<input type="radio" value="foo" v-model="bar">`).code33 ).toMatchInlineSnapshot(`34 "const { ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")35 return function ssrRender(_ctx, _push, _parent, _attrs) {36 _push(\`<div\${37 _ssrRenderAttrs(_attrs)38 }><input type=\\"radio\\" value=\\"foo\\"\${39 (_ssrLooseEqual(_ctx.bar, \\"foo\\")) ? \\" checked\\" : \\"\\"40 }></div>\`)41 }"42 `)43 })44 test('<input type="checkbox">', () => {45 expect(compileWithWrapper(`<input type="checkbox" v-model="bar">`).code)46 .toMatchInlineSnapshot(`47 "const { ssrLooseContain: _ssrLooseContain, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")48 return function ssrRender(_ctx, _push, _parent, _attrs) {49 _push(\`<div\${50 _ssrRenderAttrs(_attrs)51 }><input type=\\"checkbox\\"\${52 ((Array.isArray(_ctx.bar))53 ? _ssrLooseContain(_ctx.bar, null)54 : _ctx.bar) ? \\" checked\\" : \\"\\"55 }></div>\`)56 }"57 `)58 expect(59 compileWithWrapper(`<input type="checkbox" value="foo" v-model="bar">`)60 .code61 ).toMatchInlineSnapshot(`62 "const { ssrLooseContain: _ssrLooseContain, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")63 return function ssrRender(_ctx, _push, _parent, _attrs) {64 _push(\`<div\${65 _ssrRenderAttrs(_attrs)66 }><input type=\\"checkbox\\" value=\\"foo\\"\${67 ((Array.isArray(_ctx.bar))68 ? _ssrLooseContain(_ctx.bar, \\"foo\\")69 : _ctx.bar) ? \\" checked\\" : \\"\\"70 }></div>\`)71 }"72 `)73 expect(74 compileWithWrapper(75 `<input type="checkbox" :true-value="foo" :false-value="bar" v-model="baz">`76 ).code77 ).toMatchInlineSnapshot(`78 "const { ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")79 return function ssrRender(_ctx, _push, _parent, _attrs) {80 _push(\`<div\${81 _ssrRenderAttrs(_attrs)82 }><input type=\\"checkbox\\"\${83 (_ssrLooseEqual(_ctx.baz, _ctx.foo)) ? \\" checked\\" : \\"\\"84 }></div>\`)85 }"86 `)87 expect(88 compileWithWrapper(89 `<input type="checkbox" true-value="foo" false-value="bar" v-model="baz">`90 ).code91 ).toMatchInlineSnapshot(`92 "const { ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")93 return function ssrRender(_ctx, _push, _parent, _attrs) {94 _push(\`<div\${95 _ssrRenderAttrs(_attrs)96 }><input type=\\"checkbox\\"\${97 (_ssrLooseEqual(_ctx.baz, \\"foo\\")) ? \\" checked\\" : \\"\\"98 }></div>\`)99 }"100 `)101 })102 test('<textarea>', () => {103 expect(compileWithWrapper(`<textarea v-model="foo">bar</textarea>`).code)104 .toMatchInlineSnapshot(`105 "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")106 return function ssrRender(_ctx, _push, _parent, _attrs) {107 _push(\`<div\${108 _ssrRenderAttrs(_attrs)109 }><textarea>\${110 _ssrInterpolate(_ctx.foo)111 }</textarea></div>\`)112 }"113 `)114 })115 test('<input :type="x">', () => {116 expect(compileWithWrapper(`<input :type="x" v-model="foo">`).code)117 .toMatchInlineSnapshot(`118 "const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")119 return function ssrRender(_ctx, _push, _parent, _attrs) {120 _push(\`<div\${121 _ssrRenderAttrs(_attrs)122 }><input\${123 _ssrRenderAttr(\\"type\\", _ctx.x)124 }\${125 _ssrRenderDynamicModel(_ctx.x, _ctx.foo, null)126 }></div>\`)127 }"128 `)129 expect(130 compileWithWrapper(`<input :type="x" v-model="foo" value="bar">`).code131 ).toMatchInlineSnapshot(`132 "const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")133 return function ssrRender(_ctx, _push, _parent, _attrs) {134 _push(\`<div\${135 _ssrRenderAttrs(_attrs)136 }><input\${137 _ssrRenderAttr(\\"type\\", _ctx.x)138 }\${139 _ssrRenderDynamicModel(_ctx.x, _ctx.foo, \\"bar\\")140 } value=\\"bar\\"></div>\`)141 }"142 `)143 expect(144 compileWithWrapper(`<input :type="x" v-model="foo" :value="bar">`).code145 ).toMatchInlineSnapshot(`146 "const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")147 return function ssrRender(_ctx, _push, _parent, _attrs) {148 _push(\`<div\${149 _ssrRenderAttrs(_attrs)150 }><input\${151 _ssrRenderAttr(\\"type\\", _ctx.x)152 }\${153 _ssrRenderDynamicModel(_ctx.x, _ctx.foo, _ctx.bar)154 }\${155 _ssrRenderAttr(\\"value\\", _ctx.bar)156 }></div>\`)157 }"158 `)159 })160 test('<input v-bind="obj">', () => {161 expect(compileWithWrapper(`<input v-bind="obj" v-model="foo">`).code)162 .toMatchInlineSnapshot(`163 "const { mergeProps: _mergeProps } = require(\\"vue\\")164 const { ssrRenderAttrs: _ssrRenderAttrs, ssrGetDynamicModelProps: _ssrGetDynamicModelProps } = require(\\"@vue/server-renderer\\")165 return function ssrRender(_ctx, _push, _parent, _attrs) {166 let _temp0167 _push(\`<div\${168 _ssrRenderAttrs(_attrs)169 }><input\${170 _ssrRenderAttrs((_temp0 = _ctx.obj, _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))171 }></div>\`)172 }"173 `)174 expect(175 compileWithWrapper(`<input id="x" v-bind="obj" v-model="foo" class="y">`)176 .code177 ).toMatchInlineSnapshot(`178 "const { mergeProps: _mergeProps } = require(\\"vue\\")179 const { ssrRenderAttrs: _ssrRenderAttrs, ssrGetDynamicModelProps: _ssrGetDynamicModelProps } = require(\\"@vue/server-renderer\\")180 return function ssrRender(_ctx, _push, _parent, _attrs) {181 let _temp0182 _push(\`<div\${183 _ssrRenderAttrs(_attrs)184 }><input\${185 _ssrRenderAttrs((_temp0 = _mergeProps({ id: \\"x\\" }, _ctx.obj, { class: \\"y\\" }), _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))186 }></div>\`)187 }"188 `)189 })...

Full Screen

Full Screen

clean.js

Source:clean.js Github

copy

Full Screen

1const _ = require('lodash');2const localUtils = require('../../../index');3const tag = (attrs, frame) => {4 if (localUtils.isContentAPI(frame)) {5 const contentAttrs = _.pick(attrs, [6 'description',7 'feature_image',8 'id',9 'meta_description',10 'meta_title',11 'name',12 'slug',13 'url',14 'visibility',15 'count'16 ]);17 // We are standardising on returning null from the Content API for any empty values18 if (contentAttrs.meta_title === '') {19 contentAttrs.meta_title = null;20 }21 if (contentAttrs.meta_description === '') {22 contentAttrs.meta_description = null;23 }24 if (contentAttrs.description === '') {25 contentAttrs.description = null;26 }27 return contentAttrs;28 }29 return _.pick(attrs, [30 'created_at',31 'description',32 'feature_image',33 'id',34 'meta_description',35 'meta_title',36 'name',37 'slug',38 'updated_at',39 'url',40 'visibility',41 'count'42 ]);43};44const author = (attrs, frame) => {45 if (localUtils.isContentAPI(frame)) {46 delete attrs.created_at;47 delete attrs.updated_at;48 delete attrs.last_seen;49 delete attrs.status;50 delete attrs.email;51 // @NOTE: used for night shift52 delete attrs.accessibility;53 // Extra properties removed from v254 delete attrs.tour;55 // We are standardising on returning null from the Content API for any empty values56 if (attrs.twitter === '') {57 attrs.twitter = null;58 }59 if (attrs.bio === '') {60 attrs.bio = null;61 }62 if (attrs.website === '') {63 attrs.website = null;64 }65 if (attrs.facebook === '') {66 attrs.facebook = null;67 }68 if (attrs.meta_title === '') {69 attrs.meta_title = null;70 }71 if (attrs.meta_description === '') {72 attrs.meta_description = null;73 }74 if (attrs.location === '') {75 attrs.location = null;76 }77 }78 // @NOTE: unused fields79 delete attrs.visibility;80 delete attrs.locale;81 return attrs;82};83const post = (attrs, frame) => {84 if (localUtils.isContentAPI(frame)) {85 // @TODO: https://github.com/TryGhost/Ghost/issues/1033586 // delete attrs.page;87 delete attrs.status;88 delete attrs.email_only;89 // We are standardising on returning null from the Content API for any empty values90 if (attrs.twitter_title === '') {91 attrs.twitter_title = null;92 }93 if (attrs.twitter_description === '') {94 attrs.twitter_description = null;95 }96 if (attrs.meta_title === '') {97 attrs.meta_title = null;98 }99 if (attrs.meta_description === '') {100 attrs.meta_description = null;101 }102 if (attrs.og_title === '') {103 attrs.og_title = null;104 }105 if (attrs.og_description === '') {106 attrs.og_description = null;107 }108 delete attrs.visibility;109 } else {110 delete attrs.page;111 if (!attrs.tags) {112 delete attrs.primary_tag;113 }114 if (!attrs.authors) {115 delete attrs.primary_author;116 }117 }118 delete attrs.locale;119 delete attrs.author;120 delete attrs.type;121 delete attrs.send_email_when_published;122 delete attrs.email_recipient_filter;123 delete attrs.email_subject;124 delete attrs.feature_image_alt;125 delete attrs.feature_image_caption;126 return attrs;127};128const action = (attrs) => {129 if (attrs.actor) {130 delete attrs.actor_id;131 delete attrs.resource_id;132 if (attrs.actor_type === 'user') {133 attrs.actor = _.pick(attrs.actor, ['id', 'name', 'slug', 'profile_image']);134 attrs.actor.image = attrs.actor.profile_image;135 delete attrs.actor.profile_image;136 } else {137 attrs.actor = _.pick(attrs.actor, ['id', 'name', 'slug', 'icon_image']);138 attrs.actor.image = attrs.actor.icon_image;139 delete attrs.actor.icon_image;140 }141 } else if (attrs.resource) {142 delete attrs.actor_id;143 delete attrs.resource_id;144 // @NOTE: we only support posts right now145 attrs.resource = _.pick(attrs.resource, ['id', 'title', 'slug', 'feature_image']);146 attrs.resource.image = attrs.resource.feature_image;147 delete attrs.resource.feature_image;148 }149};150module.exports.post = post;151module.exports.tag = tag;152module.exports.author = author;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs, text, boolean, number } from '@storybook/addon-knobs/react';5import { withReadme } from 'storybook-readme';6import Readme from './README.md';7import { StoryRoot } from 'storybook-root';8const stories = storiesOf('Storybook-root', module);9stories.addDecorator(withKnobs);10stories.addDecorator(withReadme(Readme));11stories.add(12 withInfo()(() => (13 attrs={{14 title: text('title', 'Title'),15 subtitle: text('subtitle', 'Subtitle'),16 description: text('description', 'Description'),17 showTitle: boolean('showTitle', true),18 showSubtitle: boolean('showSubtitle', true),19 showDescription: boolean('showDescription', true),20 showSource: boolean('showSource', true),21 showPropTables: boolean('showPropTables', true),22 showPropTablesExclude: boolean('showPropTablesExclude', true),23 showCode: boolean('showCode', true),24 showInline: boolean('showInline', true),25 showHeader: boolean('showHeader', true),26 showFooter: boolean('showFooter', true),27 showSidebar: boolean('showSidebar', true),28 showAddonPanel: boolean('showAddonPanel', true),29 showStoriesPanel: boolean('showStoriesPanel', true),30 showAddonPanelInRight: boolean('showAddonPanelInRight', true),31 showSearchBox: boolean('showSearchBox', true),32 showNav: boolean('showNav', true),33 showPanel: boolean('showPanel', true),34 panelPosition: text('panelPosition', 'bottom'),35 sortStoriesByKind: boolean('sortStoriesByKind', true),36 hierarchySeparator: text('hierarchySeparator', '|'),37 hierarchyRootSeparator: text('hierarchyRootSeparator', '-'),38 sidebarAnimations: boolean('sidebarAnimations', true),39 enableShortcuts: boolean('enableShortcuts', true),40 isToolshown: boolean('isToolshown', true),41 theme: text('theme', 'light'),42 selectedPanel: text('selectedPanel', 'storybook/actions/actions-panel'),43 initialActive: text('initialActive', 'sidebar'),

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = document.querySelector('storybook-root');2const storybookRootAttrs = storybookRoot.attrs;3console.log(storybookRootAttrs);4const storybookPreview = document.querySelector('storybook-preview');5const storybookPreviewAttrs = storybookPreview.attrs;6console.log(storybookPreviewAttrs);7const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');8const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;9console.log(storybookPreviewIframeAttrs);10const storybookPreviewWrapper = document.querySelector('storybook-preview-wrapper');11const storybookPreviewWrapperAttrs = storybookPreviewWrapper.attrs;12console.log(storybookPreviewWrapperAttrs);13const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');14const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;15console.log(storybookPreviewIframeAttrs);16const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');17const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;18console.log(storybookPreviewIframeAttrs);19const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');20const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;21console.log(storybookPreviewIframeAttrs);22const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');23const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;24console.log(storybookPreviewIframeAttrs);25const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');26const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;27console.log(storybookPreviewIframeAttrs);28const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');29const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;30console.log(storybookPreviewIframeAttrs);

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = document.querySelector('storybook-root');2const storybookRootAttrs = storybookRoot.attrs;3console.log('storybookRootAttrs', storybookRootAttrs);4const storybookComponent = document.querySelector('storybook-component');5const storybookComponentAttrs = storybookComponent.attrs;6console.log('storybookComponentAttrs', storybookComponentAttrs);7const storybookComponent2 = document.querySelector('storybook-component');8const storybookComponentAttrs2 = storybookComponent2.attrs;9console.log('storybookComponentAttrs2', storybookComponentAttrs2);10const storybookComponent3 = document.querySelector('storybook-component');11const storybookComponentAttrs3 = storybookComponent3.attrs;12console.log('storybookComponentAttrs3', storybookComponentAttrs3);13const storybookComponent4 = document.querySelector('storybook-component');14const storybookComponentAttrs4 = storybookComponent4.attrs;15console.log('storybookComponentAttrs4', storybookComponentAttrs4);16const storybookComponent5 = document.querySelector('storybook-component');17const storybookComponentAttrs5 = storybookComponent5.attrs;18console.log('storybookComponentAttrs5', storybookComponentAttrs5);19const storybookComponent6 = document.querySelector('storybook-component');20const storybookComponentAttrs6 = storybookComponent6.attrs;21console.log('storybookComponentAttrs6', storybookComponentAttrs6);22const storybookComponent7 = document.querySelector('storybook-component');23const storybookComponentAttrs7 = storybookComponent7.attrs;24console.log('storybookComponentAttrs7', storybookComponentAttrs7);25const storybookComponent8 = document.querySelector('storybook-component');26const storybookComponentAttrs8 = storybookComponent8.attrs;27console.log('storybookComponentAttrs8', storybookComponentAttrs8);28const storybookComponent9 = document.querySelector('storybook-component');29const storybookComponentAttrs9 = storybookComponent9.attrs;30console.log('storybookComponentAttrs9', storybookComponentAttrs9);

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = document.querySelector('storybook-root');2const storybookRootAttrs = storybookRoot.attrs;3console.log(storybookRootAttrs);4const storybookPreview = document.querySelector('storybook-preview');5const storybookPreviewAttrs = storybookPreview.attrs;6console.log(storybookPreviewAttrs);7const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');8const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;9console.log(storybookPreviewIframeAttrs);10const storybookPreviewWrapper = document.querySelector('storybook-preview-wrapper');11const storybookPreviewWrapperAttrs = storybookPreviewWrapper.attrs;12console.log(storybookPreviewWrapperAttrs);13const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');14const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;15console.log(storybookPreviewIframeAttrs);16const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');17const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;18console.log(storybookPreviewIframeAttrs);19const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');20const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;21console.log(storybookPreviewIframeAttrs);22const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');23const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;24console.log(storybookPreviewIframeAttrs);25const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');26const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;27console.log(storybookPreviewIframeAttrs);28const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');29const storybookPreviewIframeAttrs = storybookPreviewIframe.attrs;30console.log(storybookPreviewIframeAttrs);

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = $('storybook-root');2console.log(storybookRoot.attrs('class'));3const storybookRoot = $('storybook-root');4console.log(storybookRoot.attrs('class'));5const storybookRoot = $('storybook-root');6console.log(storybookRoot.attrs('class'));7const storybookRoot = $('storybook-root');8console.log(storybookRoot.attrs('class'));9const storybookRoot = $('storybook-root');10console.log(storybookRoot.attrs('class'));11const storybookRoot = $('storybook-root');12console.log(storybookRoot.attrs('class'));13const storybookRoot = $('storybook-root');14console.log(storybookRoot.attrs('class'));15const storybookRoot = $('storybook-root');16console.log(storybookRoot.attrs('class'));17const storybookRoot = $('storybook-root');18console.log(storybookRoot.attrs('class'));19const storybookRoot = $('storybook-root');20console.log(storybookRoot.attrs('class'));21const storybookRoot = $('storybook-root');22console.log(storybookRoot.attrs('class'));23const storybookRoot = $('storybook-root');24console.log(storybookRoot.attrs('class'));25const storybookRoot = $('storybook-root');26console.log(storybookRoot.attrs('class'));27const storybookRoot = $('storybook-root');28console.log(storybookRoot.attrs('class'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybookRoot = docut.querySelector('storybook-root');2storybookRoot.attrs({3});4var storybookRoot = document.querySelector('storybook-root');5storybookRoot.attrs({6});7var storybookRoot = document.querySelector('storybook-root');8storybookRoot.attrs({9});10var storybookRoot = document.querySelector('storybook-root');11storybookRoot.attrs({12});13var storybookRoot = document.querySelector('storybook-root');14storybookRoot.attrs({15});16var storybookRoot = document.querySelector('storybook-root');17storybookRoot.attrs({18});19var storybookRoot = document.querySelector('storybook-root');20storybookRoot.attrs({21});22var storybookRoot = document.querySelector('storybook-root');23storybookRoot.attrs({24});25var storybookRoot = document.querySelector('storybook-root');26storybookRoot.attrs({27});28var storybookRoot = document.querySelector('storybook-root');29storybookRoot.attrs({30});31var storybookRoot = document.querySelector('storybook-root');32storybookRoot.attrs({33});34var storybookRoot = document.querySelector('storybook-root');35storybookRoot.attrs({36});37var storybookRoot = document.querySelector('storybook-root');38storybookRoot.attrs({39});

Full Screen

Using AI Code Generation

copy

Full Screen

1var storybookRoot = document.querySelector('storybook-root');2storybookRoot.attrs({3});4var storybookRoot = document.querySelector('storybook-root');5storybookRoot.attrs({6});7var storybookRoot = document.querySelector('storybook-root');8storybookRoot.attrs({9});10var storybookRoot = document.querySelector('storybook-root');11storybookRoot.attrs({12});13var storybookRoot = document.querySelector('storybook-root');14storybookRoot.attrs({15});16var storybookRoot = document.querySelector('storybook-root');17storybookRoot.attrs({18});19var storybookRoot = document.querySelector('storybook-root');20storybookRoot.attrs({21});22var storybookRoot = document.querySelector('storybook-root');23storybookRoot.attrs({24});25var storybookRoot = document.querySelector('storybook-root');26storybookRoot.attrs({27});28var storybookRoot = document.querySelector('storybook-root');29storybookRoot.attrs({30});31var storybookRoot = document.querySelector('storybook-root');32storybookRoot.attrs({33});34var storybookRoot = document.querySelector('storybook-root');35storybookRoot.attrs({36});37var storybookRoot = document.querySelector('storybook-root');38storybookRoot.attrs({39});

Full Screen

Using AI Code Generation

copy

Full Screen

1export const Root = () => {2 return (3 );4};5import { Root } from './test.js';6import { html } from 'lit-html';7import { withKnobs, text } from '@storybook/addon-knobs';8export default {9};10export const root = () => Root();11root.story = {12 parameters: {13 knobs: {14 {15 },16 },17 },18};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful