123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203 |
- //[custom Javascript]
- // Fullscreen
- $(function () {
- 'use strict'
-
- var options = {
- series: [{
- name: 'PRODUCT A',
- data: [44, 55, 41, 67, 22, 43]
- }, {
- name: 'PRODUCT B',
- data: [-44, -55, -41, -67, -22, -43]
- }],
- chart: {
- foreColor:"#bac0c7",
- type: 'bar',
- height: 350,
- stacked: true,
- toolbar: {
- show: false
- },
- zoom: {
- enabled: true
- }
- },
- responsive: [{
- breakpoint: 480,
- options: {
- legend: {
- position: 'bottom',
- offsetX: -10,
- offsetY: 0
- }
- }
- }],
- grid: {
- show: true,
- borderColor: '#f7f7f7',
- },
- colors:['#6993ff', '#f64e60'],
- plotOptions: {
- bar: {
- horizontal: false,
- columnWidth: '10%',
- endingShape: 'rounded'
- },
- },
- dataLabels: {
- enabled: false
- },
-
- xaxis: {
- type: 'datetime',
- categories: ['01/01/2011 GMT', '01/02/2011 GMT', '01/03/2011 GMT', '01/04/2011 GMT',
- '01/05/2011 GMT', '01/06/2011 GMT'
- ],
- },
- legend: {
- show: false,
- },
- fill: {
- opacity: 1
- }
- };
- var chart = new ApexCharts(document.querySelector("#charts_widget_1_chart"), options);
- chart.render();
-
-
- var options = {
- series: [{
- name: "Profit",
- data: [0, 40, 110, 70, 100, 60, 130, 55, 140, 125]
- }],
- chart: {
- foreColor:"#bac0c7",
- height: 350,
- type: 'area',
- zoom: {
- enabled: false
- }
- },
- colors:['#ea9715'],
- dataLabels: {
- enabled: false,
- },
- stroke: {
- show: true,
- curve: 'smooth',
- lineCap: 'butt',
- colors: undefined,
- width: 2,
- dashArray: 0,
- },
- markers: {
- size: 2,
- colors: '#ea9715',
- strokeColors: '#ffffff',
- strokeWidth: 2,
- strokeOpacity: 0.9,
- strokeDashArray: 0,
- fillOpacity: 1,
- discrete: [],
- shape: "circle",
- radius: 5,
- offsetX: 0,
- offsetY: 0,
- onClick: undefined,
- onDblClick: undefined,
- hover: {
- size: undefined,
- sizeOffset: 3
- }
- },
- grid: {
- borderColor: '#f7f7f7',
- row: {
- colors: ['transparent'], // takes an array which will be repeated on columns
- opacity: 0
- },
- yaxis: {
- lines: {
- show: true,
- },
- },
- },
- fill: {
- type: "gradient",
- gradient: {
- shadeIntensity: 1,
- opacityFrom: 0.01,
- opacityTo: 1,
- stops: [0, 90, 100]
- }
- },
- xaxis: {
- categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
- labels: {
- show: true,
- },
- axisBorder: {
- show: true
- },
- axisTicks: {
- show: true
- },
- tooltip: {
- enabled: true,
- },
- },
- yaxis: {
- labels: {
- show: true,
- formatter: function (val) {
- return val + "K";
- }
- }
-
- },
- };
- var chart = new ApexCharts(document.querySelector("#charts_widget_2_chart"), options);
- chart.render();
-
-
- // Composite line charts, the second using values supplied via javascript
-
- $("#linechart").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '100',
- height: '38',
- lineColor: '#f64e60',
- fillColor: '#ffffff',
- lineWidth: 2,
- minSpotColor: '#f64e60',
- maxSpotColor: '#f64e60',
- });
- $("#linechart2").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '100',
- height: '38',
- lineColor: '#faa700',
- fillColor: '#ffffff',
- lineWidth: 2,
- minSpotColor: '#faa700',
- maxSpotColor: '#faa700',
- });
- $("#linechart3").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'line',
- width: '100%',
- height: '45',
- lineColor: '#1bc5bd',
- fillColor: '#ffffff',
- lineWidth: 2,
- minSpotColor: '#f64e60',
- maxSpotColor: '#f64e60',
- });
- $("#linechart4").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '50%',
- height: '100',
- lineColor: '#1bc5bd',
- fillColor: '#ffffff',
- lineWidth: 2,
- minSpotColor: '#f64e60',
- maxSpotColor: '#f64e60',
- });
-
- $("#barchart").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'bar',
- height: '38',
- width: '100%',
- barWidth: 6,
- barSpacing: 4,
- barColor: '#3e8ef7',
- });
- $("#barchart2").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'bar',
- height: '38',
- barWidth: 6,
- barSpacing: 4,
- barColor: '#3e8ef7',
- });
- $("#barchart3").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'bar',
- height: '45',
- width: '100%',
- barWidth: 6,
- barSpacing: 4,
- barColor: '#f64e60',
- });
- $("#barchart4").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'bar',
- height: '100',
- width: '50%',
- barWidth: 6,
- barSpacing: 4,
- barColor: '#f64e60',
- });
-
- $("#discretechart").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'discrete',
- width: '50',
- height: '38',
- lineColor: '#6993ff',
- });
- $("#discretechart2").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'discrete',
- width: '50',
- height: '38',
- lineColor: '#6993ff',
- });
- $("#discretechart3").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'discrete',
- width: '180',
- height: '45',
- lineColor: '#0bb2d4',
- });
- $("#discretechart4").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'discrete',
- width: '100',
- height: '100',
- lineColor: '#0bb2d4',
- });
-
- $("#linearea").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '100%',
- height: '80',
- lineColor: '#1bc5bd',
- fillColor: '#1bc5bd',
- lineWidth: 2,
- });
- $("#linearea2").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'line',
- width: '100%',
- height: '45',
- lineColor: '#0bb2d4',
- fillColor: '#0bb2d4',
- lineWidth: 2,
- });
- $("#linearea3").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '50%',
- height: '100',
- lineColor: '#0bb2d4',
- fillColor: '#0bb2d4',
- lineWidth: 1,
- });
-
- $("#baralc").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'bar',
- height: '80',
- barWidth: 6,
- barSpacing: 4,
- barColor: '#faa700',
- });
-
- $("#lineIncrease").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '98%',
- height: '92',
- lineWidth: 2,
- lineColor: '#ffffff',
- fillColor: "rgba(255, 255, 255, 0)",
- spotColor: '#ffffff',
- minSpotColor: '#ffffff',
- maxSpotColor: '#ffffff',
- spotRadius: 1,
- });
-
- $("#lineToday").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '100%',
- height: '70',
- lineColor: '#ffffff',
- fillColor: 'rgba(255, 255, 255, 0)',
- lineWidth: 2,
- spotRadius: 3,
- });
-
- $("#baranl").sparkline([32,24,26,24,32,26,40,34,22,24,22,24,34,32,38,28,36,36,40,38,30,34,38], {
- type: 'bar',
- height: '70',
- barColor: '#f64e60',
- barWidth: 7,
- barSpacing: 5,
- });
-
- $("#lineTo").sparkline([32,24,26,24,32,26,40,34,22,24], {
- type: 'line',
- width: '100%',
- height: '70',
- lineColor: '#ffffff',
- fillColor: 'rgba(255, 255, 255, 0)',
- lineWidth: 3,
- spotColor: '#ffffff',
- highlightSpotColor: '#ffffff',
- highlightLineColor: '#ffffff',
- spotRadius: 3,
- });
-
- // donut chart
- $('.donut').peity('donut');
-
- // bar chart
- $(".bar").peity("bar");
-
-
- $('.countnm').each(function () {
- $(this).prop('Counter',0).animate({
- Counter: $(this).text()
- }, {
- duration: 1000,
- easing: 'swing',
- step: function (now) {
- $(this).text(Math.ceil(now));
- }
- });
- });
-
- }); // End of use strict
-
- // easypie chart
- $(function() {
- 'use strict'
- $('.easypie').easyPieChart({
- easing: 'easeOutBounce',
- onStep: function(from, to, percent) {
- $(this.el).find('.percent').text(Math.round(percent));
- }
- });
- var chart = window.chart = $('.easypie').data('easyPieChart');
- $('.js_update').on('click', function() {
- chart.update(Math.random()*200-100);
- });
- });// End of use strict
- // ------------------------------
- var Widgetschart = function() {
-
- // Simple bar charts
- var _barChartWidget = function(element, barQty, height, animate, easing, duration, delay, color, tooltip) {
- if (typeof d3 == 'undefined') {
- console.warn('Warning - d3.min.js is not loaded.');
- return;
- }
- // Initialize chart only if element exsists in the DOM
- if(element) {
- // Basic setup
- // ------------------------------
- // Add data set
- var bardata = [];
- for (var i=0; i < barQty; i++) {
- bardata.push(Math.round(Math.random() * 10) + 10);
- }
- // Main variables
- var d3Container = d3.select(element),
- width = d3Container.node().getBoundingClientRect().width;
-
- // Construct scales
- // ------------------------------
- // Horizontal
- var x = d3.scale.ordinal()
- .rangeBands([0, width], 0.3);
- // Vertical
- var y = d3.scale.linear()
- .range([0, height]);
- // Set input domains
- // ------------------------------
- // Horizontal
- x.domain(d3.range(0, bardata.length));
- // Vertical
- y.domain([0, d3.max(bardata)]);
- // Create chart
- // ------------------------------
- // Add svg element
- var container = d3Container.append('svg');
- // Add SVG group
- var svg = container
- .attr('width', width)
- .attr('height', height)
- .append('g');
- //
- // Append chart elements
- //
- // Bars
- var bars = svg.selectAll('rect')
- .data(bardata)
- .enter()
- .append('rect')
- .attr('class', 'd3-random-bars')
- .attr('width', x.rangeBand())
- .attr('x', function(d,i) {
- return x(i);
- })
- .style('fill', color);
- // Tooltip
- // ------------------------------
- // Initiate
- var tip = d3.tip()
- .attr('class', 'd3-tip')
- .offset([-10, 0]);
- // Show and hide
- if(tooltip == "hours" || tooltip == "goal" || tooltip == "members") {
- bars.call(tip)
- .on('mouseover', tip.show)
- .on('mouseout', tip.hide);
- }
- // Daily meetings tooltip content
- if(tooltip == "hours") {
- tip.html(function (d, i) {
- return "<div class='text-center'>" +
- "<h6 class='mb-0'>" + d + "</h6>" +
- "<span class='font-size-16'>meetings</span>" +
- "<div class='font-size-16'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Statements tooltip content
- if(tooltip == "goal") {
- tip.html(function (d, i) {
- return "<div class='text-center'>" +
- "<h6 class='mb-0'>" + d + "</h6>" +
- "<span class='font-size-16'>statements</span>" +
- "<div class='font-size-16'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Online members tooltip content
- if(tooltip == "members") {
- tip.html(function (d, i) {
- return "<div class='text-center bg-dark p-5'>" +
- "<h6 class='mb-0'>" + d + "0" + "</h6>" +
- "<span class='font-size-14'>members</span>" +
- "<div class='font-size-14'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Bar loading animation
- // ------------------------------
- // Choose between animated or static
- if(animate) {
- withAnimation();
- } else {
- withoutAnimation();
- }
- // Animate on load
- function withAnimation() {
- bars
- .attr('height', 0)
- .attr('y', height)
- .transition()
- .attr('height', function(d) {
- return y(d);
- })
- .attr('y', function(d) {
- return height - y(d);
- })
- .delay(function(d, i) {
- return i * delay;
- })
- .duration(duration)
- .ease(easing);
- }
- // Load without animateion
- function withoutAnimation() {
- bars
- .attr('height', function(d) {
- return y(d);
- })
- .attr('y', function(d) {
- return height - y(d);
- });
- }
- // Resize chart
- // ------------------------------
- // Call function on window resize
- $(window).on('resize', barsResize);
- // Call function on sidebar width change
- $(document).on('click', '.sidebar-control', barsResize);
- // Resize function
- //
- // Since D3 doesn't support SVG resize by default,
- // we need to manually specify parts of the graph that need to
- // be updated on window resize
- function barsResize() {
- // Layout variables
- width = d3Container.node().getBoundingClientRect().width;
- // Layout
- // -------------------------
- // Main svg width
- container.attr("width", width);
- // Width of appended group
- svg.attr("width", width);
- // Horizontal range
- x.rangeBands([0, width], 0.3);
- // Chart elements
- // -------------------------
- // Bars
- svg.selectAll('.d3-random-bars')
- .attr('width', x.rangeBand())
- .attr('x', function(d,i) {
- return x(i);
- });
- }
- }
- };
- // Simple line chart
- var _lineChartWidget = function(element, chartHeight, lineColor, pathColor, pointerLineColor, pointerBgColor) {
- if (typeof d3 == 'undefined') {
- console.warn('Warning - d3.min.js is not loaded.');
- return;
- }
- // Initialize chart only if element exsists in the DOM
- if(element) {
- // Basic setup
- // ------------------------------
- // Add data set
- var dataset = [
- {
- "date": "04/13/14",
- "alpha": "60"
- }, {
- "date": "04/14/14",
- "alpha": "35"
- }, {
- "date": "04/15/14",
- "alpha": "65"
- }, {
- "date": "04/16/14",
- "alpha": "50"
- }, {
- "date": "04/17/14",
- "alpha": "65"
- }, {
- "date": "04/18/14",
- "alpha": "20"
- }, {
- "date": "04/19/14",
- "alpha": "60"
- }
- ];
- // Main variables
- var d3Container = d3.select(element),
- margin = {top: 0, right: 0, bottom: 0, left: 0},
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
- height = chartHeight - margin.top - margin.bottom,
- padding = 20;
- // Format date
- var parseDate = d3.time.format("%m/%d/%y").parse,
- formatDate = d3.time.format("%a, %B %e");
- // Add tooltip
- // ------------------------------
- var tooltip = d3.tip()
- .attr('class', 'd3-tip')
- .html(function (d) {
- return "<ul class='list-unstyled mb-1 bg-dark p-5'>" +
- "<li>" + "<div class='my-1'><i class='fa fa-check mr-2'></i>" + formatDate(d.date) + "</div>" + "</li>" +
- "<li>" + "Sales: " + "<span class='float-right'>" + d.alpha + "</span>" + "</li>" +
- "<li>" + "Revenue: " + "<span class='float-right'>" + "$" + (d.alpha * 0).toFixed(2) + "</span>" + "</li>" +
- "</ul>";
- });
- // Create chart
- // ------------------------------
- // Add svg element
- var container = d3Container.append('svg');
- // Add SVG group
- var svg = container
- .attr('width', width + margin.left + margin.right)
- .attr('height', height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
- .call(tooltip);
- // Load data
- // ------------------------------
- dataset.forEach(function (d) {
- d.date = parseDate(d.date);
- d.alpha = +d.alpha;
- });
- // Construct scales
- // ------------------------------
- // Horizontal
- var x = d3.time.scale()
- .range([padding, width - padding]);
- // Vertical
- var y = d3.scale.linear()
- .range([height, 5]);
- // Set input domains
- // ------------------------------
- // Horizontal
- x.domain(d3.extent(dataset, function (d) {
- return d.date;
- }));
- // Vertical
- y.domain([0, d3.max(dataset, function (d) {
- return Math.max(d.alpha);
- })]);
- // Construct chart layout
- // ------------------------------
- // Line
- var line = d3.svg.line()
- .x(function(d) {
- return x(d.date);
- })
- .y(function(d) {
- return y(d.alpha);
- });
- //
- // Append chart elements
- //
- // Add mask for animation
- // ------------------------------
- // Add clip path
- var clip = svg.append("defs")
- .append("clipPath")
- .attr("id", "clip-line-small");
- // Add clip shape
- var clipRect = clip.append("rect")
- .attr('class', 'clip')
- .attr("width", 0)
- .attr("height", height);
- // Animate mask
- clipRect
- .transition()
- .duration(1000)
- .ease('linear')
- .attr("width", width);
- // Line
- // ------------------------------
- // Path
- var path = svg.append('path')
- .attr({
- 'd': line(dataset),
- "clip-path": "url(#clip-line-small)",
- 'class': 'd3-line d3-line-medium'
- })
- .style('stroke', lineColor);
- // Animate path
- svg.select('.line-tickets')
- .transition()
- .duration(1000)
- .ease('linear');
- // Add vertical guide lines
- // ------------------------------
- // Bind data
- var guide = svg.append('g')
- .selectAll('.d3-line-guides-group')
- .data(dataset);
- // Append lines
- guide
- .enter()
- .append('line')
- .attr('class', 'd3-line-guides')
- .attr('x1', function (d, i) {
- return x(d.date);
- })
- .attr('y1', function (d, i) {
- return height;
- })
- .attr('x2', function (d, i) {
- return x(d.date);
- })
- .attr('y2', function (d, i) {
- return height;
- })
- .style('stroke', pathColor)
- .style('stroke-dasharray', '4,2')
- .style('shape-rendering', 'crispEdges');
- // Animate guide lines
- guide
- .transition()
- .duration(1000)
- .delay(function(d, i) { return i * 150; })
- .attr('y2', function (d, i) {
- return y(d.alpha);
- });
- // Alpha app points
- // ------------------------------
- // Add points
- var points = svg.insert('g')
- .selectAll('.d3-line-circle')
- .data(dataset)
- .enter()
- .append('circle')
- .attr('class', 'd3-line-circle d3-line-circle-medium')
- .attr("cx", line.x())
- .attr("cy", line.y())
- .attr("r", 3)
- .style({
- 'stroke': pointerLineColor,
- 'fill': pointerBgColor
- });
- // Animate points on page load
- points
- .style('opacity', 0)
- .transition()
- .duration(250)
- .ease('linear')
- .delay(1000)
- .style('opacity', 1);
- // Add user interaction
- points
- .on("mouseover", function (d) {
- tooltip.offset([-10, 0]).show(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 4);
- })
- // Hide tooltip
- .on("mouseout", function (d) {
- tooltip.hide(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 3);
- });
- // Change tooltip direction of first point
- d3.select(points[0][0])
- .on("mouseover", function (d) {
- tooltip.offset([0, 10]).direction('e').show(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 4);
- })
- .on("mouseout", function (d) {
- tooltip.direction('n').hide(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 3);
- });
- // Change tooltip direction of last point
- d3.select(points[0][points.size() - 1])
- .on("mouseover", function (d) {
- tooltip.offset([0, -10]).direction('w').show(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 4);
- })
- .on("mouseout", function (d) {
- tooltip.direction('n').hide(d);
- // Animate circle radius
- d3.select(this).transition().duration(250).attr('r', 3);
- });
- // Resize chart
- // ------------------------------
- // Call function on window resize
- $(window).on('resize', lineChartResize);
- // Call function on sidebar width change
- $(document).on('click', '.sidebar-control', lineChartResize);
- // Resize function
- //
- // Since D3 doesn't support SVG resize by default,
- // we need to manually specify parts of the graph that need to
- // be updated on window resize
- function lineChartResize() {
- // Layout variables
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right;
- // Layout
- // -------------------------
- // Main svg width
- container.attr("width", width + margin.left + margin.right);
- // Width of appended group
- svg.attr("width", width + margin.left + margin.right);
- // Horizontal range
- x.range([padding, width - padding]);
- // Chart elements
- // -------------------------
- // Mask
- clipRect.attr("width", width);
- // Line path
- svg.selectAll('.d3-line').attr("d", line(dataset));
- // Circles
- svg.selectAll('.d3-line-circle').attr("cx", line.x());
- // Guide lines
- svg.selectAll('.d3-line-guides')
- .attr('x1', function (d, i) {
- return x(d.date);
- })
- .attr('x2', function (d, i) {
- return x(d.date);
- });
- }
- }
- };
- // Simple sparklines
- var _sparklinesWidget = function(element, chartType, qty, chartHeight, interpolation, duration, interval, color) {
- if (typeof d3 == 'undefined') {
- console.warn('Warning - d3.min.js is not loaded.');
- return;
- }
- // Initialize chart only if element exsists in the DOM
- if(element) {
- // Basic setup
- // ------------------------------
- // Define main variables
- var d3Container = d3.select(element),
- margin = {top: 0, right: 0, bottom: 0, left: 0},
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
- height = chartHeight - margin.top - margin.bottom;
- // Generate random data (for demo only)
- var data = [];
- for (var i=0; i < qty; i++) {
- data.push(Math.floor(Math.random() * qty) + 5);
- }
- // Construct scales
- // ------------------------------
- // Horizontal
- var x = d3.scale.linear().range([0, width]);
- // Vertical
- var y = d3.scale.linear().range([height - 5, 5]);
- // Set input domains
- // ------------------------------
- // Horizontal
- x.domain([1, qty - 3]);
- // Vertical
- y.domain([0, qty]);
-
- // Construct chart layout
- // ------------------------------
- // Line
- var line = d3.svg.line()
- .interpolate(interpolation)
- .x(function(d, i) { return x(i); })
- .y(function(d, i) { return y(d); });
- // Area
- var area = d3.svg.area()
- .interpolate(interpolation)
- .x(function(d,i) {
- return x(i);
- })
- .y0(height)
- .y1(function(d) {
- return y(d);
- });
- // Create SVG
- // ------------------------------
- // Container
- var container = d3Container.append('svg');
- // SVG element
- var svg = container
- .attr('width', width + margin.left + margin.right)
- .attr('height', height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
- // Add mask for animation
- // ------------------------------
- // Add clip path
- var clip = svg.append("defs")
- .append("clipPath")
- .attr('id', function(d, i) { return "load-clip-" + element.substring(1); });
- // Add clip shape
- var clips = clip.append("rect")
- .attr('class', 'load-clip')
- .attr("width", 0)
- .attr("height", height);
- // Animate mask
- clips
- .transition()
- .duration(1000)
- .ease('linear')
- .attr("width", width);
- //
- // Append chart elements
- //
- // Main path
- var path = svg.append("g")
- .attr("clip-path", function(d, i) { return "url(#load-clip-" + element.substring(1) + ")"; })
- .append("path")
- .datum(data)
- .attr("transform", "translate(" + x(0) + ",0)");
- // Add path based on chart type
- if(chartType == "area") {
- path.attr("d", area).attr('class', 'd3-area').style("fill", color); // area
- }
- else {
- path.attr("d", line).attr("class", "d3-line d3-line-medium").style('stroke', color); // line
- }
- // Animate path
- path
- .style('opacity', 0)
- .transition()
- .duration(500)
- .style('opacity', 1);
- // Set update interval. For demo only
- // ------------------------------
- setInterval(function() {
- // push a new data point onto the back
- data.push(Math.floor(Math.random() * qty) + 5);
- // pop the old data point off the front
- data.shift();
- update();
- }, interval);
- // Update random data. For demo only
- // ------------------------------
- function update() {
- // Redraw the path and slide it to the left
- path
- .attr("transform", null)
- .transition()
- .duration(duration)
- .ease("linear")
- .attr("transform", "translate(" + x(0) + ",0)");
- // Update path type
- if(chartType == "area") {
- path.attr("d", area).attr('class', 'd3-area').style("fill", color);
- }
- else {
- path.attr("d", line).attr("class", "d3-line d3-line-medium").style('stroke', color);
- }
- }
- // Resize chart
- // ------------------------------
- // Call function on window resize
- $(window).on('resize', resizeSparklines);
- // Call function on sidebar width change
- $(document).on('click', '.sidebar-control', resizeSparklines);
- // Resize function
- //
- // Since D3 doesn't support SVG resize by default,
- // we need to manually specify parts of the graph that need to
- // be updated on window resize
- function resizeSparklines() {
- // Layout variables
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right;
- // Layout
- // -------------------------
- // Main svg width
- container.attr("width", width + margin.left + margin.right);
- // Width of appended group
- svg.attr("width", width + margin.left + margin.right);
- // Horizontal range
- x.range([0, width]);
- // Chart elements
- // -------------------------
- // Clip mask
- clips.attr("width", width);
- // Line
- svg.select(".d3-line").attr("d", line);
- // Area
- svg.select(".d3-area").attr("d", area);
- }
- }
- };
-
- //
- // Return objects assigned to module
- //
- return {
- init: function() {
- _barChartWidget("#chart_bar_basic", 24, 50, true, "elastic", 1200, 50, "#3e8ef7", "members");
- _barChartWidget("#chart_bar_color", 24, 50, true, "elastic", 1200, 50, "rgba(255,255,255,0.75)", "members");
- _lineChartWidget('#line_chart_simple', 50, '#0bb2d4', '#0bb2d4', '#0bb2d4', '#fff');
- _lineChartWidget('#line_chart_color', 50, '#fff', 'rgba(255,255,255,0.5)', '#fff', '#29B6F6');
- _sparklinesWidget("#sparklines_basic", "area", 30, 50, "basis", 750, 2000, "#0bb2d4");
- _sparklinesWidget("#sparklines_color", "area", 30, 50, "basis", 750, 2000, "rgba(255,255,255,0.75)");
-
- }
- }
- }();
- // Initialize module
- // ------------------------------
- // When content loaded
- document.addEventListener('DOMContentLoaded', function() {
- Widgetschart.init();
- });
|