Skip to content

Commit

Permalink
Imported maps because of complicated dynamic imports from modules
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityXTech authored Jan 17, 2025
1 parent 00bf247 commit 4e5dac9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions resources/css/index.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import '../../vendor/filament/filament/resources/css/theme.css';
@import '../../node_modules/jsvectormap/dist/jsvectormap.min.css';
2 changes: 1 addition & 1 deletion resources/dist/filament-world-map-widget.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/dist/filament-world-map-widget.js

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions resources/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import jsVectorMap from 'jsvectormap';
import 'jsvectormap/dist/jsvectormap.min.css';
import 'jsvectormap/dist/maps/world.js';
import 'jsvectormap/dist/maps/world-merc.js';

/**
* Initializes the world map widget with the given options.
Expand All @@ -11,21 +12,19 @@ import 'jsvectormap/dist/jsvectormap.min.css';
* @param {string} options.selector - The CSS selector for the HTML element to attach the map
* @param {object} options.additionalOptions - Additional options to override or extend the default configuration
*/
function initWorldMapWidget({ stats, tooltipText, map, color, selector, additionalOptions = {} }) {
export default function initWorldMapWidget({
stats,
tooltipText,
map,
color,
selector,
additionalOptions = {}
}) {
return {
stats,

async init() {
const self = this;

// Dynamically import the required map file
try {
await import(`jsvectormap/dist/maps/${map.replace('_','-')}.js`);
} catch (error) {
console.error(`Error loading map: ${map}. Map file not found.`);
return;
}

const dataValues = self.stats;
const minValue = Math.min(...Object.values(dataValues));
const maxValue = Math.max(...Object.values(dataValues));
Expand Down
4 changes: 3 additions & 1 deletion resources/views/widgets/world-map-widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@use('Filament\Support\Facades\FilamentAsset')
<x-filament-widgets::widget>
<div ax-load
<div
x-ignore
ax-load
ax-load-src="{{ FilamentAsset::getAlpineComponentSrc('filament-world-map-widget', 'InfinityXTech/filament-world-map-widget') }}"
x-data="initWorldMapWidget({
stats: JSON.parse('{{ json_encode($this->stats()) }}'),
Expand Down

0 comments on commit 4e5dac9

Please sign in to comment.