diff --git a/dist/geoloop_ctrl.js b/dist/geoloop_ctrl.js index 0496462..4dc76f0 100644 --- a/dist/geoloop_ctrl.js +++ b/dist/geoloop_ctrl.js @@ -122,6 +122,8 @@ System.register(['app/plugins/sdk', 'app/core/time_series2', 'app/core/utils/kbn var _this = _possibleConstructorReturn(this, (GeoLoopCtrl.__proto__ || Object.getPrototypeOf(GeoLoopCtrl)).call(this, $scope, $injector)); + console.log('initializing geoloop control'); + _this.dataCharacteristics = {}; _this.opts = { @@ -190,6 +192,7 @@ System.register(['app/plugins/sdk', 'app/core/time_series2', 'app/core/utils/kbn _.defaults(_this.panel, panelDefaults.colorRamp); _.defaults(_this.panel, panelDefaults.sizeRamp); _.defaults(_this.panel, panelDefaults.geo); + _this.setMapProviderOpts(); _this.dataFormatter = new DataFormatter(_this, kbn); @@ -199,7 +202,8 @@ System.register(['app/plugins/sdk', 'app/core/time_series2', 'app/core/utils/kbn _this.events.on('panel-teardown', _this.onPanelTeardown.bind(_this)); _this.events.on('data-snapshot-load', _this.onDataSnapshotLoad.bind(_this)); - _this.loadGeo(); + console.log('control constructor loading geo:'); + _this.loadGeo(true); _this.lonLatStr = _this.panel.mapCenterLongitude + ',' + _this.panel.mapCenterLatitude; //$scope.$root.onAppEvent('show-dash-editor', this.doMapResize()); @@ -371,6 +375,7 @@ System.register(['app/plugins/sdk', 'app/core/time_series2', 'app/core/utils/kbn value: function updateGeoDataFeatures() { var _this4 = this; + console.log('updating geo features'); if (!this.geo || !this.geo.features) { console.log('no geo or no features'); return; @@ -379,7 +384,10 @@ System.register(['app/plugins/sdk', 'app/core/time_series2', 'app/core/utils/kbn // console.log('geojson source found. removing...'); this.map.map.removeSource('geo'); } - + if (!this.dataCharacteristics || !this.dataCharacteristics.timeValues) { + console.log('no data yet...'); + return; + } // clear timeseries data from geojson data this.dataCharacteristics.timeValues.forEach(function (tv) { _this4.geo.features.forEach(function (feature) { diff --git a/dist/geoloop_ctrl.js.map b/dist/geoloop_ctrl.js.map index 974a033..0bfa2ab 100644 --- a/dist/geoloop_ctrl.js.map +++ b/dist/geoloop_ctrl.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/geoloop_ctrl.js"],"names":["MetricsPanelCtrl","TimeSeries","kbn","contextSrv","_","d3","mapRenderer","DataFormatter","panelDefaults","mbApiKey","mapStyle","mapCenterLatitude","mapCenterLongitude","initialZoom","userInteractionEnabled","animationSpeed","animationPause","geoIdTag","geoIdPath","geo","location","contents","callback","renderType","sizeRamp","codeTo","fixedValue","measurement","auto","min","max","minValue","maxValue","showLegend","legendPosition","colorRamp","scaleName","GeoLoopCtrl","$scope","$injector","dataCharacteristics","opts","renderTypes","colorRamps","interpolateCubehelixDefault","interpolateRainbow","interpolateWarm","interpolateCool","interpolateViridis","interpolateMagma","interpolateInferno","interpolatePlasma","mapStyles","featureTypes","layerTypes","defaults","panel","setMapProviderOpts","dataFormatter","events","on","onInitEditMode","bind","onDataReceived","onPanelTeardown","onDataSnapshotLoad","loadGeo","lonLatStr","Object","keys","center","map","getCenter","lng","lat","coords","split","strVal","Number","trim","mapCenterMoved","render","remove","hardRefresh","updateRamp","user","lightTheme","saturationClass","stopAnimation","clearFrames","setStyle","updateGeoDataFeatures","reload","snapshotLocationData","window","$","ajax","type","url","contentType","jsonpCallback","dataType","success","res","console","log","fail","addEditorTab","dataList","dashboard","snapshot","series","seriesHandler","getCharacteristics","snapshotData","seriesData","datapoints","alias","target","flotpairs","getFlotPairs","nullPointMode","setZoom","features","getSource","removeSource","timeValues","forEach","tv","feature","fname","properties","keyedSeries","geoKeySearch","reStr","reg","RegExp","matches","match","length","featureId","reduce","obj","key","point","time","val","addSource","data","dc","colorInterpolator","inputRange","theRamp","scaleSequential","domain","interpolator","sizeInterpolator","px","py","scope","elem","attrs","ctrl","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACQA,sB,kBAAAA,gB;;AACDC,gB;;AACAC,S;;AACCC,gB,gBAAAA,U;;AAEDC,O;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,GAAG,CAAH,CAAP,KAAiBC,GAAG,CAAH,IAAQA,GAAG,CAAH,CAAzB,CAAD,IAAqCD,GAAG,CAAH,IAAQA,GAAG,CAAH,CAA7C,CAAhB;AAAuE,eAAhH;AACD;AACF;;;+BAIIE,K,EAAOC,I,EAAMC,K,EAAOC,I,EAAM;AAC7B5J,wBAAYyJ,KAAZ,EAAmBC,IAAnB,EAAyBC,KAAzB,EAAgCC,IAAhC;AACD;;;;QAjUsClK,gB;;yBAApBqC,W;;AAoUrBA,kBAAY8H,WAAZ,GAA0B,aAA1B","file":"geoloop_ctrl.js","sourcesContent":["/* eslint import/no-extraneous-dependencies: 0 */\nimport {MetricsPanelCtrl} from 'app/plugins/sdk';\nimport TimeSeries from 'app/core/time_series2';\nimport kbn from 'app/core/utils/kbn';\nimport {contextSrv} from 'app/core/core';\n\nimport _ from 'lodash';\nimport * as d3 from './libs/d3';\nimport mapRenderer from './map_renderer';\nimport DataFormatter from './data_formatter';\nimport './css/geoloop-panel.css!';\n\nconst panelDefaults = {\n mbApiKey: 'pk.eyXXXXXXX',\n mapStyle: 'streets-v10', // see opts below\n mapCenterLatitude: 0,\n mapCenterLongitude: 0,\n initialZoom: 8,\n userInteractionEnabled: true,\n animationSpeed: 1, // # of seconds animation time per day of data\n animationPause: 500, // millisecond pause at end of animation loop\n geoIdTag: 'geo_id',\n geoIdPath: 'id',\n geo: {\n location: 'url', // one of: url, text\n contents: 'xxxxxx', // either the jsonp url or the json text itself\n callback: 'data' // named callback in jsonp contents\n },\n renderType: 'line', // one of: line,point,polygon\n sizeRamp: {\n codeTo: 'fixed', // or 'measurement'\n fixedValue: 5,\n measurement: 'measurement_name',\n auto: false,\n min: 1,\n max: 10,\n minValue: 0,\n maxValue: 100,\n showLegend: true,\n legendPosition: 'l'\n },\n colorRamp: {\n codeTo: 'fixed', // or 'measurement'\n fixedValue: '#0000ff',\n measurement: 'measurement_name',\n auto: false,\n minValue: 1,\n maxValue: 100,\n scaleName: 'viridis', // one of D3's color ramps\n showLegend: true,\n legendPosition: 'l'\n },\n};\n\nexport default class GeoLoopCtrl extends MetricsPanelCtrl {\n constructor($scope, $injector, contextSrv) {\n super($scope, $injector);\n\n this.dataCharacteristics = {};\n\n this.opts = {\n renderTypes: ['line', 'point', 'polygon'],\n colorRamps: { /*\n for some reason, the extra d3-scale-chromatic library is hard to import ??\n 'BrBG': scale.interpolateBrBG,\n 'PRGn': scale.interpolatePRGn,\n 'PiYG': scale.interpolatePiYG,\n 'PuOr': scale.interpolatePuOr,\n 'RdBu': scale.interpolateRdBu,\n 'RdGy': scale.interpolateRdGy,\n 'RdYlBu': scale.interpolateRdYlBu,\n 'RdYlGn': scale.interpolateRdYlGn,\n 'Spectral': scale.interpolateSpectral,\n 'Blues': scale.interpolateBlues,\n 'Greens': scale.interpolateGreens,\n 'Greys': scale.interpolateGreys,\n 'Oranges': scale.interpolateOranges,\n 'Purples': scale.interpolatePurples,\n 'Reds': scale.interpolateReds,\n 'BuGn': scale.interpolateBuGn,\n 'BuPu': scale.interpolateBuPu,\n 'GnBu': scale.interpolateGnBu,\n 'OrRd': scale.interpolateOrRd,\n 'PuBuGn': scale.interpolatePuBuGn,\n 'PuBu': scale.interpolatePuBu,\n 'PuRd': scale.interpolatePuRd,\n 'RdPu': scale.interpolateRdPu,\n 'YlGnBu': scale.interpolateYlGnBu,\n 'YlGn': scale.interpolateYlGn,\n 'YlOrBr': scale.interpolateYlOrBr,\n 'YlOrRd': scale.interpolateYlOrRd */\n 'cubehelix': d3.interpolateCubehelixDefault,\n 'rainbow': d3.interpolateRainbow,\n 'warm': d3.interpolateWarm,\n 'cool': d3.interpolateCool,\n 'viridis': d3.interpolateViridis,\n 'magma': d3.interpolateMagma,\n 'inferno': d3.interpolateInferno,\n 'plasma': d3.interpolatePlasma\n },\n mapStyles: {\n 'streets': 'streets-v10',\n 'outdoors': 'outdoors-v10',\n 'light': 'light-v9',\n 'dark': 'dark-v9',\n 'satellite': 'satellite-v9',\n 'satellite-streets': 'satellite-streets-v10',\n 'traffic': 'traffic-day-v2',\n 'traffic-night': 'traffic-night-v2'\n },\n featureTypes: {\n 'Point': 'point',\n 'Line': 'line',\n 'Polygon': 'polygon'\n },\n layerTypes: {\n 'point': 'circle',\n 'polygon': 'fill',\n 'line': 'line'\n }\n };\n /* set defaults: */\n _.defaults(this.panel, panelDefaults);\n _.defaults(this.panel, panelDefaults.colorRamp);\n _.defaults(this.panel, panelDefaults.sizeRamp);\n _.defaults(this.panel, panelDefaults.geo);\n this.setMapProviderOpts();\n\n this.dataFormatter = new DataFormatter(this, kbn);\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('data-received', this.onDataReceived.bind(this));\n this.events.on('panel-teardown', this.onPanelTeardown.bind(this));\n this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));\n\n this.loadGeo();\n this.lonLatStr = this.panel.mapCenterLongitude + ',' + this.panel.mapCenterLatitude;\n\n //$scope.$root.onAppEvent('show-dash-editor', this.doMapResize());\n //$scope.$root.onAppEvent('hide-dash-editor', this.doMapResize());\n }\n\n getColorScaleImgUrl() {\n return '/public/plugins/citilogics-geoloop-panel/images/colorRamps/' + this.panel.colorRamp.scaleName + '.png';\n }\n getColorNames() {\n return Object.keys(this.opts.colorRamps);\n }\n\n setLocationFromMap() {\n const center = this.map.map.getCenter();\n this.panel.mapCenterLongitude = center.lng;\n this.panel.mapCenterLatitude = center.lat;\n this.lonLatStr = this.panel.mapCenterLongitude + ',' + this.panel.mapCenterLatitude;\n }\n\n setNewMapCenter() {\n const coords = this.lonLatStr.split(',').map((strVal) => {\n return Number(strVal.trim());\n });\n this.panel.mapCenterLongitude = coords[0];\n this.panel.mapCenterLatitude = coords[1];\n\n this.mapCenterMoved = true;\n this.render();\n }\n\n hardResetMap() {\n if (this.map) {\n this.map.remove();\n }\n this.map = null;\n this.render();\n this.hardRefresh();\n }\n\n hardRefresh() {\n this.updateRamp();\n this.loadGeo(true);\n }\n\n setMapProviderOpts() {\n if (contextSrv.user.lightTheme) {\n this.saturationClass = '';\n } else {\n this.saturationClass = 'map-darken';\n }\n\n if (this.map) {\n this.map.stopAnimation();\n this.map.clearFrames();\n this.map.map.setStyle('mapbox://styles/mapbox/' + this.panel.mapStyle).on('style.load', () => {\n this.updateGeoDataFeatures();\n this.render();\n });\n }\n }\n\n loadGeo(reload) {\n if (this.map && !reload) {\n return;\n }\n\n if (this.panel.snapshotLocationData) {\n this.geo = this.panel.snapshotLocationData;\n return;\n }\n\n if (this.panel.geo.location === 'url') {\n if (!this.panel.geo.contents) {\n return;\n }\n window.$.ajax({\n type: 'GET',\n url: this.panel.geo.contents + '?callback=?',\n contentType: 'application/json',\n jsonpCallback: this.panel.geo.callback,\n dataType: 'jsonp',\n success: (res) => {\n console.log('downloaded geojson');\n this.geo = res;\n this.updateGeoDataFeatures();\n this.render();\n }\n }).fail((res) => {\n console.log('error in ajax: ', res);\n this.geo = null;\n this.render();\n });\n } else if (this.panel.geo.location === 'text') {\n // nothing\n }\n }\n\n onPanelTeardown() {\n if (this.map) this.map.remove();\n }\n\n onInitEditMode() {\n console.log('init edit mode');\n this.addEditorTab('GeoLoop', 'public/plugins/citilogics-geoloop-panel/partials/editor.html');\n }\n\n onDataReceived(dataList) {\n // console.log('ctrl recieved data: ', dataList);\n if (!dataList) return;\n\n if (this.dashboard.snapshot && this.geo) {\n this.panel.snapshotLocationData = this.geo;\n }\n\n this.series = dataList.map(this.seriesHandler.bind(this));\n // console.log('series: ', this.series);\n this.dataCharacteristics = this.dataFormatter.getCharacteristics();\n this.updateRamp();\n this.updateGeoDataFeatures();\n this.render();\n }\n\n onDataSnapshotLoad(snapshotData) {\n this.onDataReceived(snapshotData);\n }\n\n seriesHandler(seriesData) {\n const series = new TimeSeries({\n datapoints: seriesData.datapoints,\n alias: seriesData.target,\n });\n\n series.flotpairs = series.getFlotPairs(this.panel.nullPointMode);\n return series;\n }\n\n setZoom() {\n this.map.setZoom(this.panel.initialZoom || 1);\n }\n\n toggleLegend() {\n this.render();\n }\n\n updateGeoDataFeatures() {\n if (!this.geo || !this.geo.features) {\n console.log('no geo or no features');\n return;\n }\n if (this.map && this.map.map.getSource('geo')) {\n // console.log('geojson source found. removing...');\n this.map.map.removeSource('geo');\n }\n\n // clear timeseries data from geojson data\n this.dataCharacteristics.timeValues.forEach((tv) => {\n this.geo.features.forEach((feature) => {\n const fname = 'f-' + tv;\n if (feature.properties && feature.properties[fname]) {\n delete feature.properties[fname];\n }\n });\n });\n\n\n // organize the series data - using the \"tag\" user has selected for correspondence with feature.id:\n const keyedSeries = {};\n const geoKeySearch = this.panel.geoIdTag + ':';\n const reStr = geoKeySearch + ' ([^,}]+)';\n const reg = new RegExp(reStr);\n this.series.forEach((series) => {\n // expect series.alias to be of the form --> \"measure.aggregator {tagKey: tagVal, tagKey: tagVal}\"\n const matches = series.alias.match(reg);\n // console.log('matches: ', matches);\n if (matches && matches.length > 1) {\n keyedSeries[matches[1]] = series;\n }\n });\n\n // console.log('features: ', this.geo.features);\n // console.log('keyed series: ', keyedSeries);\n\n // put data into features.\n this.geo.features.forEach((feature) => {\n if (!feature.properties) {\n feature.properties = {};\n }\n // this funny business below deserializes the dot-notation path name and resolves the feature id\n // the user has specified.\n const featureId = this.panel.geoIdPath.split('.').reduce((obj, key) => obj[key], feature);\n if (featureId in keyedSeries) {\n const series = keyedSeries[featureId];\n series.datapoints.forEach((point) => {\n const time = point[1];\n const val = point[0];\n feature.properties['f-' + time] = val;\n });\n }\n });\n\n if (this.geo && this.map) {\n console.log('adding geojson source...');\n this.map.map.addSource('geo', {\n type: 'geojson',\n data: this.geo\n });\n }\n else {\n console.log('not adding source because no map');\n }\n }\n\n\n updateRamp() { // dc :: data characteristics (dc{timeValues, min, max})\n const dc = this.dataCharacteristics;\n if (this.panel.colorRamp.codeTo === 'fixed') {\n this.panel.colorInterpolator = () => { return this.panel.colorRamp.fixedValue; };\n } else {\n const inputRange = this.panel.colorRamp.auto ? [dc.min, dc.max] : [this.panel.colorRamp.minValue, this.panel.colorRamp.maxValue];\n const theRamp = this.opts.colorRamps[this.panel.colorRamp.scaleName];\n // console.log('color ramp name: ', this.panel.colorRamp.scaleName);\n // console.log('color ramp: ', theRamp);\n this.panel.colorInterpolator = d3.scaleSequential().domain(inputRange).interpolator(theRamp);\n }\n\n if (this.panel.sizeRamp.codeTo === 'fixed') {\n this.panel.sizeInterpolator = () => { return this.panel.sizeRamp.fixedValue; };\n } else {\n const px = this.panel.sizeRamp.auto ? [dc.min, dc.max] : [this.panel.sizeRamp.minValue, this.panel.sizeRamp.maxValue];\n const py = [this.panel.sizeRamp.min, this.panel.sizeRamp.max];\n this.panel.sizeInterpolator = (val) => { return py[0] + (((val - px[0]) * (py[1] - py[0])) / (px[1] - px[0])); };\n }\n }\n\n\n/* eslint class-methods-use-this: 0 */\n link(scope, elem, attrs, ctrl) {\n mapRenderer(scope, elem, attrs, ctrl);\n }\n}\n\nGeoLoopCtrl.templateUrl = 'module.html';\n"]} \ No newline at end of file +{"version":3,"sources":["../src/geoloop_ctrl.js"],"names":["MetricsPanelCtrl","TimeSeries","kbn","contextSrv","_","d3","mapRenderer","DataFormatter","panelDefaults","mbApiKey","mapStyle","mapCenterLatitude","mapCenterLongitude","initialZoom","userInteractionEnabled","animationSpeed","animationPause","geoIdTag","geoIdPath","geo","location","contents","callback","renderType","sizeRamp","codeTo","fixedValue","measurement","auto","min","max","minValue","maxValue","showLegend","legendPosition","colorRamp","scaleName","GeoLoopCtrl","$scope","$injector","console","log","dataCharacteristics","opts","renderTypes","colorRamps","interpolateCubehelixDefault","interpolateRainbow","interpolateWarm","interpolateCool","interpolateViridis","interpolateMagma","interpolateInferno","interpolatePlasma","mapStyles","featureTypes","layerTypes","defaults","panel","setMapProviderOpts","dataFormatter","events","on","onInitEditMode","bind","onDataReceived","onPanelTeardown","onDataSnapshotLoad","loadGeo","lonLatStr","Object","keys","center","map","getCenter","lng","lat","coords","split","strVal","Number","trim","mapCenterMoved","render","remove","hardRefresh","updateRamp","user","lightTheme","saturationClass","stopAnimation","clearFrames","setStyle","updateGeoDataFeatures","reload","snapshotLocationData","window","$","ajax","type","url","contentType","jsonpCallback","dataType","success","res","fail","addEditorTab","dataList","dashboard","snapshot","series","seriesHandler","getCharacteristics","snapshotData","seriesData","datapoints","alias","target","flotpairs","getFlotPairs","nullPointMode","setZoom","features","getSource","removeSource","timeValues","forEach","tv","feature","fname","properties","keyedSeries","geoKeySearch","reStr","reg","RegExp","matches","match","length","featureId","reduce","obj","key","point","time","val","addSource","data","dc","colorInterpolator","inputRange","theRamp","scaleSequential","domain","interpolator","sizeInterpolator","px","py","scope","elem","attrs","ctrl","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACQA,sB,kBAAAA,gB;;AACDC,gB;;AACAC,S;;AACCC,gB,gBAAAA,U;;AAEDC,O;;AACKC,Q;;AACLC,iB;;AACAC,mB;;;;;;;;;;;;;;;;;;;;;AAGDC,mB,GAAgB;AACpBC,kBAAU,cADU;AAEpBC,kBAAU,aAFU,EAEK;AACzBC,2BAAmB,CAHC;AAIpBC,4BAAoB,CAJA;AAKpBC,qBAAa,CALO;AAMpBC,gCAAwB,IANJ;AAOpBC,wBAAgB,CAPI,EAOD;AACnBC,wBAAgB,GARI,EAQC;AACrBC,kBAAU,QATU;AAUpBC,mBAAW,IAVS;AAWpBC,aAAK;AACHC,oBAAU,KADP,EACc;AACjBC,oBAAU,QAFP,EAEiB;AACpBC,oBAAU,MAHP,CAGc;AAHd,SAXe;AAgBpBC,oBAAY,MAhBQ,EAgBA;AACpBC,kBAAU;AACRC,kBAAQ,OADA,EACS;AACjBC,sBAAY,CAFJ;AAGRC,uBAAa,kBAHL;AAIRC,gBAAM,KAJE;AAKRC,eAAK,CALG;AAMRC,eAAK,EANG;AAORC,oBAAU,CAPF;AAQRC,oBAAU,GARF;AASRC,sBAAY,IATJ;AAURC,0BAAgB;AAVR,SAjBU;AA6BpBC,mBAAW;AACTV,kBAAQ,OAD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sdk';\nimport TimeSeries from 'app/core/time_series2';\nimport kbn from 'app/core/utils/kbn';\nimport {contextSrv} from 'app/core/core';\n\nimport _ from 'lodash';\nimport * as d3 from './libs/d3';\nimport mapRenderer from './map_renderer';\nimport DataFormatter from './data_formatter';\nimport './css/geoloop-panel.css!';\n\nconst panelDefaults = {\n mbApiKey: 'pk.eyXXXXXXX',\n mapStyle: 'streets-v10', // see opts below\n mapCenterLatitude: 0,\n mapCenterLongitude: 0,\n initialZoom: 8,\n userInteractionEnabled: true,\n animationSpeed: 1, // # of seconds animation time per day of data\n animationPause: 500, // millisecond pause at end of animation loop\n geoIdTag: 'geo_id',\n geoIdPath: 'id',\n geo: {\n location: 'url', // one of: url, text\n contents: 'xxxxxx', // either the jsonp url or the json text itself\n callback: 'data' // named callback in jsonp contents\n },\n renderType: 'line', // one of: line,point,polygon\n sizeRamp: {\n codeTo: 'fixed', // or 'measurement'\n fixedValue: 5,\n measurement: 'measurement_name',\n auto: false,\n min: 1,\n max: 10,\n minValue: 0,\n maxValue: 100,\n showLegend: true,\n legendPosition: 'l'\n },\n colorRamp: {\n codeTo: 'fixed', // or 'measurement'\n fixedValue: '#0000ff',\n measurement: 'measurement_name',\n auto: false,\n minValue: 1,\n maxValue: 100,\n scaleName: 'viridis', // one of D3's color ramps\n showLegend: true,\n legendPosition: 'l'\n },\n};\n\nexport default class GeoLoopCtrl extends MetricsPanelCtrl {\n constructor($scope, $injector, contextSrv) {\n super($scope, $injector);\n\n console.log('initializing geoloop control');\n\n this.dataCharacteristics = {};\n\n this.opts = {\n renderTypes: ['line', 'point', 'polygon'],\n colorRamps: { /*\n for some reason, the extra d3-scale-chromatic library is hard to import ??\n 'BrBG': scale.interpolateBrBG,\n 'PRGn': scale.interpolatePRGn,\n 'PiYG': scale.interpolatePiYG,\n 'PuOr': scale.interpolatePuOr,\n 'RdBu': scale.interpolateRdBu,\n 'RdGy': scale.interpolateRdGy,\n 'RdYlBu': scale.interpolateRdYlBu,\n 'RdYlGn': scale.interpolateRdYlGn,\n 'Spectral': scale.interpolateSpectral,\n 'Blues': scale.interpolateBlues,\n 'Greens': scale.interpolateGreens,\n 'Greys': scale.interpolateGreys,\n 'Oranges': scale.interpolateOranges,\n 'Purples': scale.interpolatePurples,\n 'Reds': scale.interpolateReds,\n 'BuGn': scale.interpolateBuGn,\n 'BuPu': scale.interpolateBuPu,\n 'GnBu': scale.interpolateGnBu,\n 'OrRd': scale.interpolateOrRd,\n 'PuBuGn': scale.interpolatePuBuGn,\n 'PuBu': scale.interpolatePuBu,\n 'PuRd': scale.interpolatePuRd,\n 'RdPu': scale.interpolateRdPu,\n 'YlGnBu': scale.interpolateYlGnBu,\n 'YlGn': scale.interpolateYlGn,\n 'YlOrBr': scale.interpolateYlOrBr,\n 'YlOrRd': scale.interpolateYlOrRd */\n 'cubehelix': d3.interpolateCubehelixDefault,\n 'rainbow': d3.interpolateRainbow,\n 'warm': d3.interpolateWarm,\n 'cool': d3.interpolateCool,\n 'viridis': d3.interpolateViridis,\n 'magma': d3.interpolateMagma,\n 'inferno': d3.interpolateInferno,\n 'plasma': d3.interpolatePlasma\n },\n mapStyles: {\n 'streets': 'streets-v10',\n 'outdoors': 'outdoors-v10',\n 'light': 'light-v9',\n 'dark': 'dark-v9',\n 'satellite': 'satellite-v9',\n 'satellite-streets': 'satellite-streets-v10',\n 'traffic': 'traffic-day-v2',\n 'traffic-night': 'traffic-night-v2'\n },\n featureTypes: {\n 'Point': 'point',\n 'Line': 'line',\n 'Polygon': 'polygon'\n },\n layerTypes: {\n 'point': 'circle',\n 'polygon': 'fill',\n 'line': 'line'\n }\n };\n /* set defaults: */\n _.defaults(this.panel, panelDefaults);\n _.defaults(this.panel, panelDefaults.colorRamp);\n _.defaults(this.panel, panelDefaults.sizeRamp);\n _.defaults(this.panel, panelDefaults.geo);\n\n this.setMapProviderOpts();\n\n this.dataFormatter = new DataFormatter(this, kbn);\n\n this.events.on('init-edit-mode', this.onInitEditMode.bind(this));\n this.events.on('data-received', this.onDataReceived.bind(this));\n this.events.on('panel-teardown', this.onPanelTeardown.bind(this));\n this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));\n\n console.log('control constructor loading geo:');\n this.loadGeo(true);\n this.lonLatStr = this.panel.mapCenterLongitude + ',' + this.panel.mapCenterLatitude;\n\n //$scope.$root.onAppEvent('show-dash-editor', this.doMapResize());\n //$scope.$root.onAppEvent('hide-dash-editor', this.doMapResize());\n }\n\n getColorScaleImgUrl() {\n return '/public/plugins/citilogics-geoloop-panel/images/colorRamps/' + this.panel.colorRamp.scaleName + '.png';\n }\n getColorNames() {\n return Object.keys(this.opts.colorRamps);\n }\n\n setLocationFromMap() {\n const center = this.map.map.getCenter();\n this.panel.mapCenterLongitude = center.lng;\n this.panel.mapCenterLatitude = center.lat;\n this.lonLatStr = this.panel.mapCenterLongitude + ',' + this.panel.mapCenterLatitude;\n }\n\n setNewMapCenter() {\n const coords = this.lonLatStr.split(',').map((strVal) => {\n return Number(strVal.trim());\n });\n this.panel.mapCenterLongitude = coords[0];\n this.panel.mapCenterLatitude = coords[1];\n\n this.mapCenterMoved = true;\n this.render();\n }\n\n hardResetMap() {\n if (this.map) {\n this.map.remove();\n }\n this.map = null;\n this.render();\n this.hardRefresh();\n }\n\n hardRefresh() {\n this.updateRamp();\n this.loadGeo(true);\n }\n\n setMapProviderOpts() {\n if (contextSrv.user.lightTheme) {\n this.saturationClass = '';\n } else {\n this.saturationClass = 'map-darken';\n }\n\n if (this.map) {\n this.map.stopAnimation();\n this.map.clearFrames();\n this.map.map.setStyle('mapbox://styles/mapbox/' + this.panel.mapStyle).on('style.load', () => {\n this.updateGeoDataFeatures();\n this.render();\n });\n }\n }\n\n loadGeo(reload) {\n if (this.map && !reload) {\n return;\n }\n\n if (this.panel.snapshotLocationData) {\n this.geo = this.panel.snapshotLocationData;\n return;\n }\n\n if (this.panel.geo.location === 'url') {\n if (!this.panel.geo.contents) {\n return;\n }\n window.$.ajax({\n type: 'GET',\n url: this.panel.geo.contents + '?callback=?',\n contentType: 'application/json',\n jsonpCallback: this.panel.geo.callback,\n dataType: 'jsonp',\n success: (res) => {\n console.log('downloaded geojson');\n this.geo = res;\n this.updateGeoDataFeatures();\n this.render();\n }\n }).fail((res) => {\n console.log('error in ajax: ', res);\n this.geo = null;\n this.render();\n });\n } else if (this.panel.geo.location === 'text') {\n // nothing\n }\n }\n\n onPanelTeardown() {\n if (this.map) this.map.remove();\n }\n\n onInitEditMode() {\n console.log('init edit mode');\n this.addEditorTab('GeoLoop', 'public/plugins/citilogics-geoloop-panel/partials/editor.html');\n }\n\n onDataReceived(dataList) {\n // console.log('ctrl recieved data: ', dataList);\n if (!dataList) return;\n\n if (this.dashboard.snapshot && this.geo) {\n this.panel.snapshotLocationData = this.geo;\n }\n\n this.series = dataList.map(this.seriesHandler.bind(this));\n // console.log('series: ', this.series);\n this.dataCharacteristics = this.dataFormatter.getCharacteristics();\n this.updateRamp();\n this.updateGeoDataFeatures();\n this.render();\n }\n\n onDataSnapshotLoad(snapshotData) {\n this.onDataReceived(snapshotData);\n }\n\n seriesHandler(seriesData) {\n const series = new TimeSeries({\n datapoints: seriesData.datapoints,\n alias: seriesData.target,\n });\n\n series.flotpairs = series.getFlotPairs(this.panel.nullPointMode);\n return series;\n }\n\n setZoom() {\n this.map.setZoom(this.panel.initialZoom || 1);\n }\n\n toggleLegend() {\n this.render();\n }\n\n updateGeoDataFeatures() {\n console.log('updating geo features');\n if (!this.geo || !this.geo.features) {\n console.log('no geo or no features');\n return;\n }\n if (this.map && this.map.map.getSource('geo')) {\n // console.log('geojson source found. removing...');\n this.map.map.removeSource('geo');\n }\n if (!this.dataCharacteristics || !this.dataCharacteristics.timeValues) {\n console.log('no data yet...');\n return;\n }\n // clear timeseries data from geojson data\n this.dataCharacteristics.timeValues.forEach((tv) => {\n this.geo.features.forEach((feature) => {\n const fname = 'f-' + tv;\n if (feature.properties && feature.properties[fname]) {\n delete feature.properties[fname];\n }\n });\n });\n\n\n // organize the series data - using the \"tag\" user has selected for correspondence with feature.id:\n const keyedSeries = {};\n const geoKeySearch = this.panel.geoIdTag + ':';\n const reStr = geoKeySearch + ' ([^,}]+)';\n const reg = new RegExp(reStr);\n this.series.forEach((series) => {\n // expect series.alias to be of the form --> \"measure.aggregator {tagKey: tagVal, tagKey: tagVal}\"\n const matches = series.alias.match(reg);\n // console.log('matches: ', matches);\n if (matches && matches.length > 1) {\n keyedSeries[matches[1]] = series;\n }\n });\n\n // console.log('features: ', this.geo.features);\n // console.log('keyed series: ', keyedSeries);\n\n // put data into features.\n this.geo.features.forEach((feature) => {\n if (!feature.properties) {\n feature.properties = {};\n }\n // this funny business below deserializes the dot-notation path name and resolves the feature id\n // the user has specified.\n const featureId = this.panel.geoIdPath.split('.').reduce((obj, key) => obj[key], feature);\n if (featureId in keyedSeries) {\n const series = keyedSeries[featureId];\n series.datapoints.forEach((point) => {\n const time = point[1];\n const val = point[0];\n feature.properties['f-' + time] = val;\n });\n }\n });\n\n if (this.geo && this.map) {\n console.log('adding geojson source...');\n this.map.map.addSource('geo', {\n type: 'geojson',\n data: this.geo\n });\n }\n else {\n console.log('not adding source because no map');\n }\n }\n\n\n updateRamp() { // dc :: data characteristics (dc{timeValues, min, max})\n const dc = this.dataCharacteristics;\n if (this.panel.colorRamp.codeTo === 'fixed') {\n this.panel.colorInterpolator = () => { return this.panel.colorRamp.fixedValue; };\n } else {\n const inputRange = this.panel.colorRamp.auto ? [dc.min, dc.max] : [this.panel.colorRamp.minValue, this.panel.colorRamp.maxValue];\n const theRamp = this.opts.colorRamps[this.panel.colorRamp.scaleName];\n // console.log('color ramp name: ', this.panel.colorRamp.scaleName);\n // console.log('color ramp: ', theRamp);\n this.panel.colorInterpolator = d3.scaleSequential().domain(inputRange).interpolator(theRamp);\n }\n\n if (this.panel.sizeRamp.codeTo === 'fixed') {\n this.panel.sizeInterpolator = () => { return this.panel.sizeRamp.fixedValue; };\n } else {\n const px = this.panel.sizeRamp.auto ? [dc.min, dc.max] : [this.panel.sizeRamp.minValue, this.panel.sizeRamp.maxValue];\n const py = [this.panel.sizeRamp.min, this.panel.sizeRamp.max];\n this.panel.sizeInterpolator = (val) => { return py[0] + (((val - px[0]) * (py[1] - py[0])) / (px[1] - px[0])); };\n }\n }\n\n\n/* eslint class-methods-use-this: 0 */\n link(scope, elem, attrs, ctrl) {\n mapRenderer(scope, elem, attrs, ctrl);\n }\n\n}\n\nGeoLoopCtrl.templateUrl = 'module.html';\n"]} \ No newline at end of file diff --git a/dist/map_renderer.js b/dist/map_renderer.js index 985f927..a92b3a2 100644 --- a/dist/map_renderer.js +++ b/dist/map_renderer.js @@ -6,7 +6,7 @@ System.register(['./geoloop'], function (_export, _context) { var GeoLoop; function link(scope, elem, attrs, ctrl) { var mapContainer = elem.find('.mapcontainer'); - // console.log('found: ', mapContainer); + console.log('initialized map renderer'); ctrl.events.on('render', function () { render(); @@ -19,6 +19,7 @@ System.register(['./geoloop'], function (_export, _context) { }); function render() { + console.log("called into RENDER"); if (!ctrl.map) { // console.log('creating new map'); ctrl.map = new GeoLoop(ctrl, mapContainer[0]); diff --git a/dist/map_renderer.js.map b/dist/map_renderer.js.map index c85a307..16794b9 100644 --- a/dist/map_renderer.js.map +++ b/dist/map_renderer.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/map_renderer.js"],"names":["link","scope","elem","attrs","ctrl","mapContainer","find","events","on","render","map","setTimeout","resize","renderingCompleted","GeoLoop","mapCenterMoved","panToMapCenter","legend","panel","showLegend","createLegend","updateRamp","drawLayerFrames"],"mappings":";;;;;;AAEe,WAASA,IAAT,CAAcC,KAAd,EAAqBC,IAArB,EAA2BC,KAA3B,EAAkCC,IAAlC,EAAwC;AACrD,QAAMC,eAAeH,KAAKI,IAAL,CAAU,eAAV,CAArB;AACA;;AAEAF,SAAKG,MAAL,CAAYC,EAAZ,CAAe,QAAf,EAAyB,YAAM;AAC7BC;AACA,UAAIL,KAAKM,GAAT,EAAc;AACZC,mBAAW,YAAM;AACfP,eAAKM,GAAL,CAASE,MAAT;AACD,SAFD,EAEG,GAFH;AAGD;AACDR,WAAKS,kBAAL;AACD,KARD;;AAUA,aAASJ,MAAT,GAAkB;AAChB,UAAI,CAACL,KAAKM,GAAV,EAAe;AACb;AACAN,aAAKM,GAAL,GAAW,IAAII,OAAJ,CAAYV,IAAZ,EAAkBC,aAAa,CAAb,CAAlB,CAAX;AACD;;AAEDD,WAAKM,GAAL,CAASE,MAAT;;AAEA,UAAIR,KAAKW,cAAT,EAAyBX,KAAKM,GAAL,CAASM,cAAT;;AAEzB,UAAI,CAACZ,KAAKM,GAAL,CAASO,MAAV,IAAoBb,KAAKc,KAAL,CAAWC,UAAnC,EAA+Cf,KAAKM,GAAL,CAASU,YAAT;;AAE/ChB,WAAKiB,UAAL;AACAjB,WAAKM,GAAL,CAASY,eAAT;AACD;AACF;;qBA7BuBtB,I;;;;AAFjBc,a","file":"map_renderer.js","sourcesContent":["import GeoLoop from './geoloop';\n\nexport default function link(scope, elem, attrs, ctrl) {\n const mapContainer = elem.find('.mapcontainer');\n // console.log('found: ', mapContainer);\n\n ctrl.events.on('render', () => {\n render();\n if (ctrl.map) {\n setTimeout(() => {\n ctrl.map.resize();\n }, 500);\n }\n ctrl.renderingCompleted();\n });\n\n function render() {\n if (!ctrl.map) {\n // console.log('creating new map');\n ctrl.map = new GeoLoop(ctrl, mapContainer[0]);\n }\n\n ctrl.map.resize();\n\n if (ctrl.mapCenterMoved) ctrl.map.panToMapCenter();\n\n if (!ctrl.map.legend && ctrl.panel.showLegend) ctrl.map.createLegend();\n\n ctrl.updateRamp();\n ctrl.map.drawLayerFrames();\n }\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../src/map_renderer.js"],"names":["link","scope","elem","attrs","ctrl","mapContainer","find","console","log","events","on","render","map","setTimeout","resize","renderingCompleted","GeoLoop","mapCenterMoved","panToMapCenter","legend","panel","showLegend","createLegend","updateRamp","drawLayerFrames"],"mappings":";;;;;;AAEe,WAASA,IAAT,CAAcC,KAAd,EAAqBC,IAArB,EAA2BC,KAA3B,EAAkCC,IAAlC,EAAwC;AACrD,QAAMC,eAAeH,KAAKI,IAAL,CAAU,eAAV,CAArB;AACAC,YAAQC,GAAR,CAAY,0BAAZ;;AAEAJ,SAAKK,MAAL,CAAYC,EAAZ,CAAe,QAAf,EAAyB,YAAM;AAC7BC;AACA,UAAIP,KAAKQ,GAAT,EAAc;AACZC,mBAAW,YAAM;AACfT,eAAKQ,GAAL,CAASE,MAAT;AACD,SAFD,EAEG,GAFH;AAGD;AACDV,WAAKW,kBAAL;AACD,KARD;;AAUA,aAASJ,MAAT,GAAkB;AAChBJ,cAAQC,GAAR,CAAY,oBAAZ;AACA,UAAI,CAACJ,KAAKQ,GAAV,EAAe;AACb;AACAR,aAAKQ,GAAL,GAAW,IAAII,OAAJ,CAAYZ,IAAZ,EAAkBC,aAAa,CAAb,CAAlB,CAAX;AACD;;AAEDD,WAAKQ,GAAL,CAASE,MAAT;;AAEA,UAAIV,KAAKa,cAAT,EAAyBb,KAAKQ,GAAL,CAASM,cAAT;;AAEzB,UAAI,CAACd,KAAKQ,GAAL,CAASO,MAAV,IAAoBf,KAAKgB,KAAL,CAAWC,UAAnC,EAA+CjB,KAAKQ,GAAL,CAASU,YAAT;;AAE/ClB,WAAKmB,UAAL;AACAnB,WAAKQ,GAAL,CAASY,eAAT;AACD;AACF;;qBA9BuBxB,I;;;;AAFjBgB,a","file":"map_renderer.js","sourcesContent":["import GeoLoop from './geoloop';\n\nexport default function link(scope, elem, attrs, ctrl) {\n const mapContainer = elem.find('.mapcontainer');\n console.log('initialized map renderer');\n\n ctrl.events.on('render', () => {\n render();\n if (ctrl.map) {\n setTimeout(() => {\n ctrl.map.resize();\n }, 500);\n }\n ctrl.renderingCompleted();\n });\n\n function render() {\n console.log(\"called into RENDER\");\n if (!ctrl.map) {\n // console.log('creating new map');\n ctrl.map = new GeoLoop(ctrl, mapContainer[0]);\n }\n\n ctrl.map.resize();\n\n if (ctrl.mapCenterMoved) ctrl.map.panToMapCenter();\n\n if (!ctrl.map.legend && ctrl.panel.showLegend) ctrl.map.createLegend();\n\n ctrl.updateRamp();\n ctrl.map.drawLayerFrames();\n }\n}\n"]} \ No newline at end of file diff --git a/src/geoloop_ctrl.js b/src/geoloop_ctrl.js index 1f60187..42095d4 100644 --- a/src/geoloop_ctrl.js +++ b/src/geoloop_ctrl.js @@ -56,6 +56,8 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { constructor($scope, $injector, contextSrv) { super($scope, $injector); + console.log('initializing geoloop control'); + this.dataCharacteristics = {}; this.opts = { @@ -124,6 +126,7 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { _.defaults(this.panel, panelDefaults.colorRamp); _.defaults(this.panel, panelDefaults.sizeRamp); _.defaults(this.panel, panelDefaults.geo); + this.setMapProviderOpts(); this.dataFormatter = new DataFormatter(this, kbn); @@ -133,7 +136,8 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { this.events.on('panel-teardown', this.onPanelTeardown.bind(this)); this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this)); - this.loadGeo(); + console.log('control constructor loading geo:'); + this.loadGeo(true); this.lonLatStr = this.panel.mapCenterLongitude + ',' + this.panel.mapCenterLatitude; //$scope.$root.onAppEvent('show-dash-editor', this.doMapResize()); @@ -280,6 +284,7 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { } updateGeoDataFeatures() { + console.log('updating geo features'); if (!this.geo || !this.geo.features) { console.log('no geo or no features'); return; @@ -288,7 +293,10 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { // console.log('geojson source found. removing...'); this.map.map.removeSource('geo'); } - + if (!this.dataCharacteristics || !this.dataCharacteristics.timeValues) { + console.log('no data yet...'); + return; + } // clear timeseries data from geojson data this.dataCharacteristics.timeValues.forEach((tv) => { this.geo.features.forEach((feature) => { @@ -374,6 +382,7 @@ export default class GeoLoopCtrl extends MetricsPanelCtrl { link(scope, elem, attrs, ctrl) { mapRenderer(scope, elem, attrs, ctrl); } + } GeoLoopCtrl.templateUrl = 'module.html'; diff --git a/src/map_renderer.js b/src/map_renderer.js index 8c2641b..8d8461e 100644 --- a/src/map_renderer.js +++ b/src/map_renderer.js @@ -2,7 +2,7 @@ import GeoLoop from './geoloop'; export default function link(scope, elem, attrs, ctrl) { const mapContainer = elem.find('.mapcontainer'); - // console.log('found: ', mapContainer); + console.log('initialized map renderer'); ctrl.events.on('render', () => { render(); @@ -15,6 +15,7 @@ export default function link(scope, elem, attrs, ctrl) { }); function render() { + console.log("called into RENDER"); if (!ctrl.map) { // console.log('creating new map'); ctrl.map = new GeoLoop(ctrl, mapContainer[0]);