Skip to content

Instantly share code, notes, and snippets.

@induprasad
induprasad / strikecmp.js
Created April 24, 2018 07:27
JS file required to be uploaded as static resource for using the strike chart component
// https://d3js.org Version 4.2.6. Copyright 2016 Mike Bostock.
(function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3=t.d3||{})})(this,function(t){"use strict";function n(t){return function(n,e){return ms(t(n),e)}}function e(t,n,e){var r=Math.abs(n-t)/Math.max(0,e),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),o=r/i;return o>=Rs?i*=10:o>=Us?i*=5:o>=Ds&&(i*=2),n<t?-i:i}function r(t){return t.length}function i(){}function o(t,n){var e=new i;if(t instanceof i)t.each(function(t,n){e.set(n,t)});else if(Array.isArray(t)){var r,o=-1,u=t.length;if(null==n)for(;++o<u;)e.set(o,t[o]);else for(;++o<u;)e.set(n(r=t[o],o,t),r)}else if(t)for(var a in t)e.set(a,t[a]);return e}function u(){return{}}function a(t,n,e){t[n]=e}function c(){return o()}function s(t,n,e){t.set(n,e)}function f(){}function l(t,n){var e=new f;if(t instanceof f)t.each(function(t){e.add(t)});else if(t){var r=-1,i=t.length;if(null==n)for(;++r<i;)e.add(t[r]);else
@induprasad
induprasad / LCC_CaseResults
Created April 24, 2018 08:21
Apex class to retrieve cases, accounts and their status
global without sharing class LCC_CaseResults {
@AuraEnabled
public static List<CaseViewResults> getAllCases() {
LIST<Case> filteredCases = new LIST<Case>();
LIST<Account> filteredAccounts = new LIST<Account>();
LIST<CaseViewResults> results = new LIST<CaseViewResults>();
Map<String, Case> recordSet = new Map<String, Case>();
SET<String> accountIds = new SET<String>();
@induprasad
induprasad / LCMP_StrikeChart.cmp
Last active May 3, 2018 12:56
Lightning component for forming Chart
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global" >
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
<ltng:require scripts="/resource/StrikeCmpResource" afterScriptsLoaded="{!c.onInit}"/>
<aura:attribute name="scriptsLoaded" type="Boolean" default="{!false}"/>
<aura:attribute name="chartRendered" type="Boolean" default="{!false}" description="Flag to display the loading spinner."/>
<aura:attribute name="triggerRedraw" type="Boolean" access="private" default="{!false}" description="Flag that triggers redraw of the chart."/>
<aura:attribute name="displayAxis" type="Boolean" access="private" default="{!false}" description="Flag that triggers displaying the left and bottom axis labels."/>
@induprasad
induprasad / LCMP_StrikeChartController.js
Last active April 25, 2018 06:33
Controller of the LCMP_Strike component
({
//Function called on Init
onInit: function (component, event, helper) {
var data = component.get("v.data");
component.set('v.scriptsLoaded', true);
component.set('v.triggerRedraw', !component.get('v.triggerRedraw'));
component.resize = $A.getCallback(function () {
if (component.isValid()) {
component.set('v.fontSize', helper.determineFontSize(component.get('v.containerWidth')));
component.set('v.chartRendered', false);
@induprasad
induprasad / LCMP_StrikeChartHelper.js
Created May 3, 2018 12:53
Helper of LCMP_StrikeChart component
({
//Function which draws the bar chart
barChart: function (component, helper) {
component.set('v.displayAxis', true);
var dataset = component.get("v.data"); //The data retrieved from the controller or parent component
var color = helper.getColors(); //Setting the colors to the bars
//Setting the orientation of the chart as vertical, can also be turned to horizontal
var isVertical = component.get('v.orientation') === 'vertical';
@induprasad
induprasad / LCMP_StrikeChartRenderer.js
Created May 3, 2018 13:03
Renderer of the LCMP_StrikeChart component
({
rerender: function (component, helper) {
this.superRerender();
if (!component.get('v.scriptsLoaded') || component.get('v.chartRendered')) {
return;
}
//make sure threshold isn't a string
component.get('v.thresholdValue', parseInt(component.get('v.thresholdValue')));
var containerWidth = component.find('chartContainer').getElement().clientWidth;
.THIS .sc-axis-label {
color: #bfbebe;
}
.THIS .sc-axis-value {
color: white;
font-size: 13px;
}
.THIS .sc-tooltip {
@induprasad
induprasad / LCMP_DisplayChart.cmp
Created May 3, 2018 13:18
Component used to pass values to the strike component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global" controller="LCC_CaseResults">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
<aura:attribute name="barData" type="Object[]" />
<aura:attribute name="accountName" type="String" default="" />
<aura:attribute name="divLength" type="String" default="4" />
<aura:attribute name="opencases" type="String" default="Open Cases" />
<aura:attribute name="closedcases" type="String" default="Closed cases" />
<aura:attribute name="totalcases" type="String" default="{!$Label.c.CLR417CCCTotalCases}" />
@induprasad
induprasad / LCMP_DisplayChartController.js
Created May 3, 2018 13:20
Controller of LCMP_DisplayChart component
({
getResponse: function(component, event, helper) {
helper.getCases(component);
}
})
@induprasad
induprasad / LCMP_DisplayChartHelper.js
Created May 3, 2018 13:23
Helper of the LCMP_DisplayChart component
({
//Generic Method to perform server calls
callToServer: function(component, method, callback, params) {
component.set("v.showSpinner", true);
var action = component.get(method);
action.setStorable();
if(params) {
action.setParams(params);
}
action.setCallback(this, function(response) {