Highchart overflows modal window - angularjs

In this plunk I have a Highcharts chart in an Angular UI modal window. The modal window has height and width declared in a class, and the chart is supposed to strech to width/height however it overflows at the bottom (possibly because it has two divs on top with text). How to make it fit?
Note: the chart has to be below the text divs, not as background.
HTML:
<script type="text/ng-template" id="myModalContent.html">
<div>some text</div>
<div>more text</div>
<div id="container" style="min-width: 300px; width:100%; height:100%;"> </div>
</script>
<button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
Javascript:
var app = angular.module("app", ['ui.bootstrap']);
app.controller("ctl", function($scope,$uibModal,$timeout) {
var modalInstance;
$scope.open = function () {
modalInstance = $uibModal.open({
animation: false,
windowClass: 'the-modal',
templateUrl: 'myModalContent.html'
});
$timeout(function(){
plotChart();
});
};
var plotChart = function(){
$('#container').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Berlin',
data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
});
};
});

That is right, the presence of child div elements and setting height:100%; for chart container cause overflow for the parent container. One option to fix this issue is to use CSS3's Flexible Box Layout Module, another options are listed in this answer.
Using CSS3's Flexible Box Layout Module
Enable a Flexbox Layout for a parent container (modal dialog)
.the-modal .modal-content{ display: flex; flex-direction: column; }
and then set chart container to occupy the remaining space via flex-grow, in your case replace:
<div id="container" style="min-width: 300px; width:100%; height:100%;"></div>
with
<div id="container" style="min-width: 300px; width:100%; flex-grow: 1;"></div>
Updated plunker

Related

Focus custom md-checkbox in md-select control

I have implemented select control with select all option, When I open the control, it focuses on the first option. I would like to focus on the select option or at least disable the focus.
HTML
<div ng-app="selectDemoOptGroups" ng-controller="SelectOptGroupController" >
<md-select md-selected-text="selectedText" ng-model="selectedToppings" multiple>
<div class="select-all-div" >
<md-checkbox class="select-selectAll"
>Select all</md-checkbox > </div>
<md-option ng-value="topping.name" ng-repeat="topping in toppings">{{topping.name}}</md-option>
</md-select>
JS
angular
.module('selectDemoOptGroups', ['ngMaterial'])
.controller('SelectOptGroupController', function($scope) {
$scope.toppings = [
{ category: 'meat', name: 'Pepperoni' },
{ category: 'meat', name: 'Sausage' },
{ category: 'meat', name: 'Ground Beef' },
{ category: 'meat', name: 'Bacon' },
{ category: 'veg', name: 'Mushrooms' },
{ category: 'veg', name: 'Onion' },
{ category: 'veg', name: 'Green Pepper' },
{ category: 'veg', name: 'Green Olives' }
];
$scope.selectedToppings = [];
});
https://jsfiddle.net/AlexLavriv/ya6eu8kz/5/
You can't use a div for single opotion and options for the rest. You can use the same option to display the option select all.
<md-select>
<md-option>Select all</md-option>
<md-option ng-value="topping.name" ng-repeat="topping in toppings">{{topping.name}}</md-option>
</md-select>
Working Demo: JSFiDDLE
Working Demo
Try this below way
angular
.module('selectDemoOptGroups', ['ngMaterial'])
.controller('SelectOptGroupController', function($scope) {
$scope.toppings = [
{ category: 'meat', name: 'Pepperoni' },
{ category: 'meat', name: 'Sausage' },
{ category: 'meat', name: 'Ground Beef' },
{ category: 'meat', name: 'Bacon' },
{ category: 'veg', name: 'Mushrooms' },
{ category: 'veg', name: 'Onion' },
{ category: 'veg', name: 'Green Pepper' },
{ category: 'veg', name: 'Green Olives' }
];
$scope.toppings.unshift( { category: 'select', name: 'Select all' })
$scope.selectedText = $scope.toppings[0].name;
});
.select-selectAll{
text-align: left;
padding-left: 10px;
/* padding-right: 16px; */
display: flex;
cursor: pointer;
position: relative !important;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center;
width: 95%;
-webkit-transition: background .15s linear;
transition: background .15s linear;
/* padding: 0 16px; */
height: 48px;
}
.select-selectAll div.md-icon{
left:10px;
}
.select-all-div:hover{
background: rgb(238,238,238);
}
<div ng-app="selectDemoOptGroups" ng-controller="SelectOptGroupController" >
<md-select md-selected-text="selectedText" ng-model="selectedToppings" multiple>
<md-option ng-value="topping.name" ng-repeat="topping in toppings">{{topping.name}}</md-option>
</md-select>
</div>

Reusing methods in AngularJS instead of defining multiple variables

I've created a sample application in angularjs.
I've different variables(colorNew and numberNew) which hold the value of similar operation.
How can I optimize the code(create a method), so that I can reuse my angular.forEach as well as split method shown in the code instead of writing them multiple times?
Here's the code:
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope){
$scope.myData = [
{
'car': 'Ford',
'color': 'Black, White, Blue',
'number': '1, 2, 3',
'model': 'Figo'
}, {
'car': 'Ford',
'color': 'Red, Black, Silver',
'number': '4,5',
'model': 'Endeavour'
},{
'car': 'Jaguar',
'color': 'White',
'number': '6',
'model': 'F-Type'
},
];
$scope.getData = function(){
$scope.color = this.car.color.split(',');
$scope.number = this.car.number.split(',');
console.log($scope.color);
$scope.colorNew = angular.forEach($scope.color, function() {
return $(this);
}).join(' | ');
$scope.numberNew = angular.forEach($scope.number, function() {
return $(this);
}).join(' | ');
console.log($scope.colorNew);
console.log($scope.numberNew);
};
}]);
.parent {
border: 1px solid lightgrey;
border-radius: 5px;
background-color: skyblue;
height: 100px;
margin-top: 5px;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<button id="createData">Create Data</button>
<div class="container">
<div ng-repeat="car in myData" class="parent">
<div>
<label>Car:</label>
<span>{{car.car}}</span>
</div>
<br />
<div>
<label>Model:</label>
<span>{{car.model}}</span>
</div>
<br />
<button ng-click="getData(obj)">Click Me!</button>
</div>
</div>
</div>

Customize the expand/ collapse button in ext js grid/ accordion

Is there any way to customise the expand(+)/ collapse(-) buttons in ExtJs grid/ accordion.
You can change the icons by overriding the CSS for tool icons. You can add a class name to the accordion panel and apply styles to the tool buttons using that.
Sample Code Snippet
Ext.create('Ext.panel.Panel', {
title: 'Accordion Layout',
width: 200,
height: 300,
layout: {
type: 'accordion'
},
cls: 'my-accordion',
items: [{
title: 'Panel 1',
html: 'Panel content!'
}, {
title: 'Panel 2',
html: 'Panel content!',
collapsed: true
}, {
title: 'Panel 3',
html: 'Panel content!',
collapsed: true
}],
renderTo: Ext.get("container")
});
body {
padding: 0px;
}
.my-accordion .x-accordion-hd .x-tool-over .x-tool-collapse-top,
.my-accordion .x-accordion-hd .x-tool-over .x-tool-collapse-bottom,
.my-accordion .x-accordion-hd .x-tool-collapse-top,
.my-accordion .x-accordion-hd .x-tool-collapse-bottom {
background-position: 0 -570px;
}
.my-accordion .x-accordion-hd .x-tool-over .x-tool-expand-top,
.my-accordion .x-accordion-hd .x-tool-over .x-tool-expand-bottom,
.my-accordion .x-accordion-hd .x-tool-expand-top,
.my-accordion .x-accordion-hd .x-tool-expand-bottom {
background-position: 0 525px;
}
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext-4.2.0-gpl/resources/css/ext-all.css">
<div id="container">
</div>

Angular google maps. Access maps default functions

im working on a google map thing where i need to access the setZoom method when clicking on a custom button. The problem is that setZoom() gets undefined. I have loaded all dependencies(the map renders and my $scope.zoom runs). I have tested that. Anyone knows how to do?
html:
<div ng-app="app" ng-controller="MapController">
<ui-gmap-google-map center="map.center" zoom="map.zoom">
<ui-gmap-map-control template="../pages/partials/map-controls.html" controller="MapController" position="RIGHT_BOTTOM">
</ui-gmap-map-control>
</ui-gmap-google-map>
</div>
js:
$scope.map = {
center: {
latitude: 67.855800,
longitude: 20.225282
},
zoom: 13,
options: {
scrollwheel: false,
disableDefaultUI: true,
streetViewControl: false,
backgroundColor: '#f2f2f2'
}
};
$scope.zoom = function($event) {
$event.preventDefault();
//the problem is here. $scope.map.setZoom() gets undefined.
$scope.map.setZoom(9);
};
I think you want to call
$scope.map.control.getGMap().setZoom(9);
instead of
$scope.map.setZoom(9);
See the example controller for more info - https://github.com/angular-ui/angular-google-maps/blob/cbd17a3a225dfe543faa124eb295e66db566f27c/example/assets/scripts/controllers/example.js
--- updating example
html:
<div ng-app="app" ng-controller="MapController">
<ui-gmap-google-map
center="map.center"
zoom="map.zoom"
options="map.options"
control="map.control>
<ui-gmap-map-control
template="../pages/partials/map-controls.html"
controller="MapController"
position="RIGHT_BOTTOM">
</ui-gmap-map-control>
</ui-gmap-google-map>
</div>
js:
scope.map = {
center: {
latitude: 67.855800,
longitude: 20.225282
},
control: {},
zoom: 13,
options: {
scrollwheel: false,
disableDefaultUI: true,
streetViewControl: false,
backgroundColor: '#f2f2f2'
}
};
$scope.zoom = function($event) {
$event.preventDefault();
//the problem is here. $scope.map.setZoom() gets undefined.
$scope.map.setZoom(9);
};
--- adding example
angular
.module('app', ['uiGmapgoogle-maps'])
.controller('MapController', mapController)
mapController.$inject = ['$scope', 'uiGmapIsReady'];
function mapController($scope, uiGmapIsReady) {
$scope.map = {
center: {
latitude: 67.855800,
longitude: 20.225282
},
control: {},
zoom: 13,
options: {
scrollwheel: false,
disableDefaultUI: true,
streetViewControl: false,
backgroundColor: '#f2f2f2'
}
};
$scope.zoom = function($event) {
$scope.map.control.getGMap().setZoom(9);
};
uiGmapIsReady
.promise()
.then(function (maps) {
// ready to manip map
});
};
html, body, #map_canvas {
height: 200px;
width: 200px;
margin: 0px;
}
#map_canvas {
position: relative;
}
.angular-google-map-container {
position: absolute;
top: 20px;
bottom: 0;
right: 0;
left: 0;
}
<!DOCTYPE html>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script src="http://rawgit.com/angular-ui/angular-google-maps/2.0.X/dist/angular-google-maps.js"></script>
<script type='text/javascript' src='script.js'></script>
<div ng-app='app' id='map_canvas' ng-controller='MapController'>
<button ng-click='zoom()'>Set Zoom</button>
<ui-gmap-google-map
center="map.center"
zoom="map.zoom"
control="map.control">
</ui-gmap-google-map>
</div>

(Kendo UI, Angular) Pie Chart will not center

My markup is as follows:
<div id="severity-piechart">
<div ng-controller="SingleDetailsPieCtrl">
<div kendo-chart k-theme="'metro'" k-title="{ text: 'All Issues', positon: 'top' }"
k-series-defaults="{ type: 'pie',
labels: {
visible: true,
background: 'transparent',
template: '#= category #: \n #= value#'
} }"
k-series=" [{ data: [{category: 'Issues', value: 14, color: '#FF0044'},
{category: 'Warnings', value: 4, color: '#FFD023'},
{category: 'Messages', value: 2, color: '#0B6FE8'}],
}]"
k-legend="{ visible: false }"
style="height: 35vh" >
</div>
</div>
</div>
Whenever I try the example located here I can do whatever I want to the chart as long as I touch the style attribute. However when I do the same in this example:
<div id="severity-piechart">
<div ng-controller="SingleDetailsPieCtrl">
<div kendo-chart k-theme="'metro'" k-title="{ text: 'All Issues', positon: 'top' }"
k-series-defaults="{ type: 'pie',
labels: { visible: true, background: 'transparent',
template: '#= category #: \n #= value#' } }"
k-series=" [{data: [{category: 'Issues', value: 14, color: '#FF0044'},
{category: 'Warnings', value: 4, color: '#FFD023'},
{category: 'Messages', value: 2, color: '#0B6FE8'}],
}]"
k-legend="{ visible: false }"
style="height: 35vh; width: 50%; margin: 0 auto; display: block;" >
</div>
</div>
</div>
The chart becomes incredibly small, it's not centered, and all of the labels are clipped.
Has anyone encountered a similar situation?

Resources