@opendatasoft/visualizations
Version:
Opendatasoft's components to easily build dashboards and visualizations.
1,585 lines (1,568 loc) • 475 kB
JavaScript
import { Chart, defaults, registerables } from 'chart.js';
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap';
import DataLabels from 'chartjs-plugin-datalabels';
import Stacked100Plugin from 'chartjs-plugin-stacked100';
import update$1 from 'immutability-helper';
import 'chartjs-adapter-luxon';
import { DateTime } from 'luxon';
import { geoPath, geoMercator } from 'd3-geo';
import chroma from 'chroma-js';
import turfBbox from '@turf/bbox';
import maplibregl from 'maplibre-gl';
import { viewport } from '@placemarkio/geo-viewport';
import { debounce, isEqual, difference, toNumber, isNil } from 'lodash';
import tippy from 'tippy.js';
import mila from 'markdown-it-link-attributes';
import MarkdownItMark from 'markdown-it-mark';
import MarkdownIt from 'markdown-it';
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function () {
return !!t;
})();
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : String(i);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function noop() { }
function assign(tar, src) {
// @ts-ignore
for (const k in src)
tar[k] = src[k];
return tar;
}
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
let src_url_equal_anchor;
function src_url_equal(element_src, url) {
if (!src_url_equal_anchor) {
src_url_equal_anchor = document.createElement('a');
}
src_url_equal_anchor.href = url;
return element_src === src_url_equal_anchor.href;
}
function not_equal(a, b) {
return a != a ? b == b : a !== b;
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function subscribe(store, ...callbacks) {
if (store == null) {
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
}
function create_slot(definition, ctx, $$scope, fn) {
if (definition) {
const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
return definition[0](slot_ctx);
}
}
function get_slot_context(definition, ctx, $$scope, fn) {
return definition[1] && fn
? assign($$scope.ctx.slice(), definition[1](fn(ctx)))
: $$scope.ctx;
}
function get_slot_changes(definition, $$scope, dirty, fn) {
if (definition[2] && fn) {
const lets = definition[2](fn(dirty));
if ($$scope.dirty === undefined) {
return lets;
}
if (typeof lets === 'object') {
const merged = [];
const len = Math.max($$scope.dirty.length, lets.length);
for (let i = 0; i < len; i += 1) {
merged[i] = $$scope.dirty[i] | lets[i];
}
return merged;
}
return $$scope.dirty | lets;
}
return $$scope.dirty;
}
function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
if (slot_changes) {
const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
slot.p(slot_context, slot_changes);
}
}
function get_all_dirty_from_scope($$scope) {
if ($$scope.ctx.length > 32) {
const dirty = [];
const length = $$scope.ctx.length / 32;
for (let i = 0; i < length; i++) {
dirty[i] = -1;
}
return dirty;
}
return -1;
}
function exclude_internal_props(props) {
const result = {};
for (const k in props)
if (k[0] !== '$')
result[k] = props[k];
return result;
}
function null_to_empty(value) {
return value == null ? '' : value;
}
function set_store_value(store, ret, value) {
store.set(value);
return ret;
}
function action_destroyer(action_result) {
return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
}
function append(target, node) {
target.appendChild(node);
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element(name) {
return document.createElement(name);
}
function svg_element(name) {
return document.createElementNS('http://www.w3.org/2000/svg', name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(' ');
}
function empty() {
return text('');
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function set_svg_attributes(node, attributes) {
for (const key in attributes) {
attr(node, key, attributes[key]);
}
}
function children(element) {
return Array.from(element.childNodes);
}
function set_data(text, data) {
data = '' + data;
if (text.data === data)
return;
text.data = data;
}
function set_style(node, key, value, important) {
if (value == null) {
node.style.removeProperty(key);
}
else {
node.style.setProperty(key, value, '');
}
}
function select_option(select, value, mounting) {
for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i];
if (option.__value === value) {
option.selected = true;
return;
}
}
if (!mounting || value !== undefined) {
select.selectedIndex = -1; // no option should be selected
}
}
function select_value(select) {
const selected_option = select.querySelector(':checked');
return selected_option && selected_option.__value;
}
// unfortunately this can't be a constant as that wouldn't be tree-shakeable
// so we cache the result instead
let crossorigin;
function is_crossorigin() {
if (crossorigin === undefined) {
crossorigin = false;
try {
if (typeof window !== 'undefined' && window.parent) {
void window.parent.document;
}
}
catch (error) {
crossorigin = true;
}
}
return crossorigin;
}
function add_iframe_resize_listener(node, fn) {
const computed_style = getComputedStyle(node);
if (computed_style.position === 'static') {
node.style.position = 'relative';
}
const iframe = element('iframe');
iframe.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; ' +
'overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;');
iframe.setAttribute('aria-hidden', 'true');
iframe.tabIndex = -1;
const crossorigin = is_crossorigin();
let unsubscribe;
if (crossorigin) {
iframe.src = "data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>";
unsubscribe = listen(window, 'message', (event) => {
if (event.source === iframe.contentWindow)
fn();
});
}
else {
iframe.src = 'about:blank';
iframe.onload = () => {
unsubscribe = listen(iframe.contentWindow, 'resize', fn);
// make sure an initial resize event is fired _after_ the iframe is loaded (which is asynchronous)
// see https://github.com/sveltejs/svelte/issues/4233
fn();
};
}
append(node, iframe);
return () => {
if (crossorigin) {
unsubscribe();
}
else if (unsubscribe && iframe.contentWindow) {
unsubscribe();
}
detach(iframe);
};
}
function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error('Function called outside component initialization');
return current_component;
}
/**
* The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.
* It must be called during the component's initialisation (but doesn't need to live *inside* the component;
* it can be called from an external module).
*
* `onMount` does not run inside a [server-side component](/docs#run-time-server-side-component-api).
*
* https://svelte.dev/docs#run-time-svelte-onmount
*/
function onMount(fn) {
get_current_component().$$.on_mount.push(fn);
}
/**
* Schedules a callback to run immediately before the component is unmounted.
*
* Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the
* only one that runs inside a server-side component.
*
* https://svelte.dev/docs#run-time-svelte-ondestroy
*/
function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}
/**
* Associates an arbitrary `context` object with the current component and the specified `key`
* and returns that object. The context is then available to children of the component
* (including slotted content) with `getContext`.
*
* Like lifecycle functions, this must be called during component initialisation.
*
* https://svelte.dev/docs#run-time-svelte-setcontext
*/
function setContext(key, context) {
get_current_component().$$.context.set(key, context);
return context;
}
/**
* Retrieves the context that belongs to the closest parent component with the specified `key`.
* Must be called during component initialisation.
*
* https://svelte.dev/docs#run-time-svelte-getcontext
*/
function getContext(key) {
return get_current_component().$$.context.get(key);
}
// TODO figure out if we still want to support
// shorthand events, or if we want to implement
// a real bubbling mechanism
function bubble(component, event) {
const callbacks = component.$$.callbacks[event.type];
if (callbacks) {
// @ts-ignore
callbacks.slice().forEach(fn => fn.call(this, event));
}
}
const dirty_components = [];
const binding_callbacks = [];
let render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = /* @__PURE__ */ Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
// flush() calls callbacks in this order:
// 1. All beforeUpdate callbacks, in order: parents before children
// 2. All bind:this callbacks, in reverse order: children before parents.
// 3. All afterUpdate callbacks, in order: parents before children. EXCEPT
// for afterUpdates called during the initial onMount, which are called in
// reverse order: children before parents.
// Since callbacks might update component values, which could trigger another
// call to flush(), the following steps guard against this:
// 1. During beforeUpdate, any updated components will be added to the
// dirty_components array and will cause a reentrant call to flush(). Because
// the flush index is kept outside the function, the reentrant call will pick
// up where the earlier call left off and go through all dirty components. The
// current_component value is saved and restored so that the reentrant call will
// not interfere with the "parent" flush() call.
// 2. bind:this callbacks cannot trigger new flush() calls.
// 3. During afterUpdate, any updated components will NOT have their afterUpdate
// callback called a second time; the seen_callbacks set, outside the flush()
// function, guarantees this behavior.
const seen_callbacks = new Set();
let flushidx = 0; // Do *not* move this inside the flush() function
function flush() {
// Do not reenter flush while dirty components are updated, as this can
// result in an infinite loop. Instead, let the inner flush handle it.
// Reentrancy is ok afterwards for bindings etc.
if (flushidx !== 0) {
return;
}
const saved_component = current_component;
do {
// first, call beforeUpdate functions
// and update components
try {
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
}
catch (e) {
// reset dirty state to not end up in a deadlocked state and then rethrow
dirty_components.length = 0;
flushidx = 0;
throw e;
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
seen_callbacks.clear();
set_current_component(saved_component);
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
/**
* Useful for example to execute remaining `afterUpdate` callbacks before executing `destroy`.
*/
function flush_render_callbacks(fns) {
const filtered = [];
const targets = [];
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
targets.forEach((c) => c());
render_callbacks = filtered;
}
const outroing = new Set();
let outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros // parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach)
block.d(1);
callback();
}
});
block.o(local);
}
else if (callback) {
callback();
}
}
function outro_and_destroy_block(block, lookup) {
transition_out(block, 1, 1, () => {
lookup.delete(block.key);
});
}
function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, next, get_context) {
let o = old_blocks.length;
let n = list.length;
let i = o;
const old_indexes = {};
while (i--)
old_indexes[old_blocks[i].key] = i;
const new_blocks = [];
const new_lookup = new Map();
const deltas = new Map();
const updates = [];
i = n;
while (i--) {
const child_ctx = get_context(ctx, list, i);
const key = get_key(child_ctx);
let block = lookup.get(key);
if (!block) {
block = create_each_block(key, child_ctx);
block.c();
}
else {
// defer updates until all the DOM shuffling is done
updates.push(() => block.p(child_ctx, dirty));
}
new_lookup.set(key, new_blocks[i] = block);
if (key in old_indexes)
deltas.set(key, Math.abs(i - old_indexes[key]));
}
const will_move = new Set();
const did_move = new Set();
function insert(block) {
transition_in(block, 1);
block.m(node, next);
lookup.set(block.key, block);
next = block.first;
n--;
}
while (o && n) {
const new_block = new_blocks[n - 1];
const old_block = old_blocks[o - 1];
const new_key = new_block.key;
const old_key = old_block.key;
if (new_block === old_block) {
// do nothing
next = new_block.first;
o--;
n--;
}
else if (!new_lookup.has(old_key)) {
// remove old block
destroy(old_block, lookup);
o--;
}
else if (!lookup.has(new_key) || will_move.has(new_key)) {
insert(new_block);
}
else if (did_move.has(old_key)) {
o--;
}
else if (deltas.get(new_key) > deltas.get(old_key)) {
did_move.add(new_key);
insert(new_block);
}
else {
will_move.add(old_key);
o--;
}
}
while (o--) {
const old_block = old_blocks[o];
if (!new_lookup.has(old_block.key))
destroy(old_block, lookup);
}
while (n)
insert(new_blocks[n - 1]);
run_all(updates);
return new_blocks;
}
function get_spread_update(levels, updates) {
const update = {};
const to_null_out = {};
const accounted_for = { $$scope: 1 };
let i = levels.length;
while (i--) {
const o = levels[i];
const n = updates[i];
if (n) {
for (const key in o) {
if (!(key in n))
to_null_out[key] = 1;
}
for (const key in n) {
if (!accounted_for[key]) {
update[key] = n[key];
accounted_for[key] = 1;
}
}
levels[i] = n;
}
else {
for (const key in o) {
accounted_for[key] = 1;
}
}
}
for (const key in to_null_out) {
if (!(key in update))
update[key] = undefined;
}
return update;
}
function get_spread_object(spread_props) {
return typeof spread_props === 'object' && spread_props !== null ? spread_props : {};
}
function create_component(block) {
block && block.c();
}
function mount_component(component, target, anchor, customElement) {
const { fragment, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
// if the component was destroyed immediately
// it will update the `$$.on_destroy` reference to `null`.
// the destructured on_destroy may still reference to the old array
if (component.$$.on_destroy) {
component.$$.on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
flush_render_callbacks($$.after_update);
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: [],
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles && append_styles($$.root);
let ready = false;
$$.ctx = instance
? instance(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
})
: [];
$$.update();
ready = true;
run_all($$.before_update);
// `false` as a special case of no DOM component
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor, options.customElement);
flush();
}
set_current_component(parent_component);
}
/**
* Base class for Svelte components. Used when dev=false.
*/
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
if (!is_function(callback)) {
return noop;
}
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}
function create_fragment$L(ctx) {
var div;
var t;
return {
c: function c() {
div = element("div");
t = text( /*label*/ctx[0]);
attr(div, "class", "svelte-1tgk8p4");
},
m: function m(target, anchor) {
insert(target, div, anchor);
append(div, t);
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
if (dirty & /*label*/1) set_data(t, /*label*/ctx[0]);
},
i: noop,
o: noop,
d: function d(detaching) {
if (detaching) detach(div);
}
};
}
function instance$K($$self, $$props, $$invalidate) {
var label = $$props.label;
$$self.$$set = function ($$props) {
if ('label' in $$props) $$invalidate(0, label = $$props.label);
};
return [label];
}
var CategoryLegendItemLabel = /*#__PURE__*/function (_SvelteComponent) {
_inherits(CategoryLegendItemLabel, _SvelteComponent);
function CategoryLegendItemLabel(options) {
var _this;
_classCallCheck(this, CategoryLegendItemLabel);
_this = _callSuper(this, CategoryLegendItemLabel);
init(_assertThisInitialized(_this), options, instance$K, create_fragment$L, not_equal, {
label: 0
});
return _this;
}
return _createClass(CategoryLegendItemLabel);
}(SvelteComponent);
var LEGEND_POSITIONS = {
bottom: 'bottom',
left: 'left',
right: 'right'
};
var CATEGORY_ITEM_VARIANT = {
Circle: 'circle',
Line: 'line',
Box: 'box',
Image: 'image'
};
function create_fragment$K(ctx) {
var div;
return {
c: function c() {
div = element("div");
set_style(div, "--box-color", /*item*/ctx[0].color);
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
attr(div, "class", "svelte-1rxbf04");
},
m: function m(target, anchor) {
insert(target, div, anchor);
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
if (dirty & /*item*/1) {
set_style(div, "--box-color", /*item*/ctx[0].color);
}
if (dirty & /*item*/1) {
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
}
},
i: noop,
o: noop,
d: function d(detaching) {
if (detaching) detach(div);
}
};
}
function instance$J($$self, $$props, $$invalidate) {
var item = $$props.item;
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
};
return [item];
}
var BoxSymbol = /*#__PURE__*/function (_SvelteComponent) {
_inherits(BoxSymbol, _SvelteComponent);
function BoxSymbol(options) {
var _this;
_classCallCheck(this, BoxSymbol);
_this = _callSuper(this, BoxSymbol);
init(_assertThisInitialized(_this), options, instance$J, create_fragment$K, not_equal, {
item: 0
});
return _this;
}
return _createClass(BoxSymbol);
}(SvelteComponent);
function create_fragment$J(ctx) {
var div;
return {
c: function c() {
div = element("div");
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
attr(div, "class", "svelte-4v1cor");
toggle_class(div, "dashed", /*item*/ctx[0].dashed);
},
m: function m(target, anchor) {
insert(target, div, anchor);
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
if (dirty & /*item*/1) {
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
}
if (dirty & /*item*/1) {
toggle_class(div, "dashed", /*item*/ctx[0].dashed);
}
},
i: noop,
o: noop,
d: function d(detaching) {
if (detaching) detach(div);
}
};
}
function instance$I($$self, $$props, $$invalidate) {
var item = $$props.item;
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
};
return [item];
}
var LineSymbol = /*#__PURE__*/function (_SvelteComponent) {
_inherits(LineSymbol, _SvelteComponent);
function LineSymbol(options) {
var _this;
_classCallCheck(this, LineSymbol);
_this = _callSuper(this, LineSymbol);
init(_assertThisInitialized(_this), options, instance$I, create_fragment$J, not_equal, {
item: 0
});
return _this;
}
return _createClass(LineSymbol);
}(SvelteComponent);
function create_fragment$I(ctx) {
var div;
return {
c: function c() {
div = element("div");
set_style(div, "--box-color", /*item*/ctx[0].color);
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
attr(div, "class", "svelte-qkxkos");
},
m: function m(target, anchor) {
insert(target, div, anchor);
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
if (dirty & /*item*/1) {
set_style(div, "--box-color", /*item*/ctx[0].color);
}
if (dirty & /*item*/1) {
set_style(div, "--border-color", /*item*/ctx[0].borderColor);
}
},
i: noop,
o: noop,
d: function d(detaching) {
if (detaching) detach(div);
}
};
}
function instance$H($$self, $$props, $$invalidate) {
var item = $$props.item;
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
};
return [item];
}
var CircleSymbol = /*#__PURE__*/function (_SvelteComponent) {
_inherits(CircleSymbol, _SvelteComponent);
function CircleSymbol(options) {
var _this;
_classCallCheck(this, CircleSymbol);
_this = _callSuper(this, CircleSymbol);
init(_assertThisInitialized(_this), options, instance$H, create_fragment$I, not_equal, {
item: 0
});
return _this;
}
return _createClass(CircleSymbol);
}(SvelteComponent);
function create_fragment$H(ctx) {
var img;
var img_src_value;
return {
c: function c() {
img = element("img");
if (!src_url_equal(img.src, img_src_value = /*item*/ctx[0].src)) attr(img, "src", img_src_value);
attr(img, "class", "svelte-hp7ez8");
},
m: function m(target, anchor) {
insert(target, img, anchor);
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
if (dirty & /*item*/1 && !src_url_equal(img.src, img_src_value = /*item*/ctx[0].src)) {
attr(img, "src", img_src_value);
}
},
i: noop,
o: noop,
d: function d(detaching) {
if (detaching) detach(img);
}
};
}
function instance$G($$self, $$props, $$invalidate) {
var item = $$props.item;
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
};
return [item];
}
var ImageSymbol = /*#__PURE__*/function (_SvelteComponent) {
_inherits(ImageSymbol, _SvelteComponent);
function ImageSymbol(options) {
var _this;
_classCallCheck(this, ImageSymbol);
_this = _callSuper(this, ImageSymbol);
init(_assertThisInitialized(_this), options, instance$G, create_fragment$H, not_equal, {
item: 0
});
return _this;
}
return _createClass(ImageSymbol);
}(SvelteComponent);
function create_if_block_3$8(ctx) {
var imagesymbol;
var current;
imagesymbol = new ImageSymbol({
props: {
item: /*item*/ctx[0]
}
});
return {
c: function c() {
create_component(imagesymbol.$$.fragment);
},
m: function m(target, anchor) {
mount_component(imagesymbol, target, anchor);
current = true;
},
p: function p(ctx, dirty) {
var imagesymbol_changes = {};
if (dirty & /*item*/1) imagesymbol_changes.item = /*item*/ctx[0];
imagesymbol.$set(imagesymbol_changes);
},
i: function i(local) {
if (current) return;
transition_in(imagesymbol.$$.fragment, local);
current = true;
},
o: function o(local) {
transition_out(imagesymbol.$$.fragment, local);
current = false;
},
d: function d(detaching) {
destroy_component(imagesymbol, detaching);
}
};
}
// (13:54)
function create_if_block_2$8(ctx) {
var linesymbol;
var current;
linesymbol = new LineSymbol({
props: {
item: /*item*/ctx[0]
}
});
return {
c: function c() {
create_component(linesymbol.$$.fragment);
},
m: function m(target, anchor) {
mount_component(linesymbol, target, anchor);
current = true;
},
p: function p(ctx, dirty) {
var linesymbol_changes = {};
if (dirty & /*item*/1) linesymbol_changes.item = /*item*/ctx[0];
linesymbol.$set(linesymbol_changes);
},
i: function i(local) {
if (current) return;
transition_in(linesymbol.$$.fragment, local);
current = true;
},
o: function o(local) {
transition_out(linesymbol.$$.fragment, local);
current = false;
},
d: function d(detaching) {
destroy_component(linesymbol, detaching);
}
};
}
// (11:53)
function create_if_block_1$c(ctx) {
var boxsymbol;
var current;
boxsymbol = new BoxSymbol({
props: {
item: /*item*/ctx[0]
}
});
return {
c: function c() {
create_component(boxsymbol.$$.fragment);
},
m: function m(target, anchor) {
mount_component(boxsymbol, target, anchor);
current = true;
},
p: function p(ctx, dirty) {
var boxsymbol_changes = {};
if (dirty & /*item*/1) boxsymbol_changes.item = /*item*/ctx[0];
boxsymbol.$set(boxsymbol_changes);
},
i: function i(local) {
if (current) return;
transition_in(boxsymbol.$$.fragment, local);
current = true;
},
o: function o(local) {
transition_out(boxsymbol.$$.fragment, local);
current = false;
},
d: function d(detaching) {
destroy_component(boxsymbol, detaching);
}
};
}
// (9:0) {#if item.variant === CATEGORY_ITEM_VARIANT.Circle}
function create_if_block$l(ctx) {
var circlesymbol;
var current;
circlesymbol = new CircleSymbol({
props: {
item: /*item*/ctx[0]
}
});
return {
c: function c() {
create_component(circlesymbol.$$.fragment);
},
m: function m(target, anchor) {
mount_component(circlesymbol, target, anchor);
current = true;
},
p: function p(ctx, dirty) {
var circlesymbol_changes = {};
if (dirty & /*item*/1) circlesymbol_changes.item = /*item*/ctx[0];
circlesymbol.$set(circlesymbol_changes);
},
i: function i(local) {
if (current) return;
transition_in(circlesymbol.$$.fragment, local);
current = true;
},
o: function o(local) {
transition_out(circlesymbol.$$.fragment, local);
current = false;
},
d: function d(detaching) {
destroy_component(circlesymbol, detaching);
}
};
}
function create_fragment$G(ctx) {
var current_block_type_index;
var if_block;
var if_block_anchor;
var current;
var if_block_creators = [create_if_block$l, create_if_block_1$c, create_if_block_2$8, create_if_block_3$8];
var if_blocks = [];
function select_block_type(ctx, dirty) {
if ( /*item*/ctx[0].variant === CATEGORY_ITEM_VARIANT.Circle) return 0;
if ( /*item*/ctx[0].variant === CATEGORY_ITEM_VARIANT.Box) return 1;
if ( /*item*/ctx[0].variant === CATEGORY_ITEM_VARIANT.Line) return 2;
if ( /*item*/ctx[0].variant === CATEGORY_ITEM_VARIANT.Image) return 3;
return -1;
}
if (~(current_block_type_index = select_block_type(ctx))) {
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
}
return {
c: function c() {
if (if_block) if_block.c();
if_block_anchor = empty();
},
m: function m(target, anchor) {
if (~current_block_type_index) {
if_blocks[current_block_type_index].m(target, anchor);
}
insert(target, if_block_anchor, anchor);
current = true;
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
var previous_block_index = current_block_type_index;
current_block_type_index = select_block_type(ctx);
if (current_block_type_index === previous_block_index) {
if (~current_block_type_index) {
if_blocks[current_block_type_index].p(ctx, dirty);
}
} else {
if (if_block) {
group_outros();
transition_out(if_blocks[previous_block_index], 1, 1, function () {
if_blocks[previous_block_index] = null;
});
check_outros();
}
if (~current_block_type_index) {
if_block = if_blocks[current_block_type_index];
if (!if_block) {
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
if_block.c();
} else {
if_block.p(ctx, dirty);
}
transition_in(if_block, 1);
if_block.m(if_block_anchor.parentNode, if_block_anchor);
} else {
if_block = null;
}
}
},
i: function i(local) {
if (current) return;
transition_in(if_block);
current = true;
},
o: function o(local) {
transition_out(if_block);
current = false;
},
d: function d(detaching) {
if (~current_block_type_index) {
if_blocks[current_block_type_index].d(detaching);
}
if (detaching) detach(if_block_anchor);
}
};
}
function instance$F($$self, $$props, $$invalidate) {
var item = $$props.item;
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
};
return [item];
}
var CategoryLegendItemSymbol = /*#__PURE__*/function (_SvelteComponent) {
_inherits(CategoryLegendItemSymbol, _SvelteComponent);
function CategoryLegendItemSymbol(options) {
var _this;
_classCallCheck(this, CategoryLegendItemSymbol);
_this = _callSuper(this, CategoryLegendItemSymbol);
init(_assertThisInitialized(_this), options, instance$F, create_fragment$G, not_equal, {
item: 0
});
return _this;
}
return _createClass(CategoryLegendItemSymbol);
}(SvelteComponent);
function create_if_block$k(ctx) {
var categorylegenditemlabel;
var current;
categorylegenditemlabel = new CategoryLegendItemLabel({
props: {
label: /*stringLabel*/ctx[4]
}
});
return {
c: function c() {
create_component(categorylegenditemlabel.$$.fragment);
},
m: function m(target, anchor) {
mount_component(categorylegenditemlabel, target, anchor);
current = true;
},
p: function p(ctx, dirty) {
var categorylegenditemlabel_changes = {};
if (dirty & /*stringLabel*/16) categorylegenditemlabel_changes.label = /*stringLabel*/ctx[4];
categorylegenditemlabel.$set(categorylegenditemlabel_changes);
},
i: function i(local) {
if (current) return;
transition_in(categorylegenditemlabel.$$.fragment, local);
current = true;
},
o: function o(local) {
transition_out(categorylegenditemlabel.$$.fragment, local);
current = false;
},
d: function d(detaching) {
destroy_component(categorylegenditemlabel, detaching);
}
};
}
function create_fragment$F(ctx) {
var div;
var categorylegenditemsymbol;
var t;
var div_tabindex_value;
var current;
var mounted;
var dispose;
categorylegenditemsymbol = new CategoryLegendItemSymbol({
props: {
item: /*item*/ctx[0]
}
});
var if_block = /*stringLabel*/ctx[4] && create_if_block$k(ctx);
return {
c: function c() {
div = element("div");
create_component(categorylegenditemsymbol.$$.fragment);
t = space();
if (if_block) if_block.c();
attr(div, "role", "button");
attr(div, "tabindex", div_tabindex_value = /*item*/ctx[0].onClick ? 0 : -1);
set_style(div, "--cursor-style", /*item*/ctx[0].onClick ? 'pointer' : 'default');
attr(div, "class", "svelte-12d3x5b");
toggle_class(div, "refined", /*refined*/ctx[3]);
},
m: function m(target, anchor) {
insert(target, div, anchor);
mount_component(categorylegenditemsymbol, div, null);
append(div, t);
if (if_block) if_block.m(div, null);
current = true;
if (!mounted) {
dispose = [listen(div, "keydown", /*onKeyDown*/ctx[5]), listen(div, "click", /*click_handler*/ctx[6]), listen(div, "mouseenter", /*mouseenter_handler*/ctx[7]), listen(div, "mouseleave", /*mouseleave_handler*/ctx[8])];
mounted = true;
}
},
p: function p(ctx, _ref) {
var _ref2 = _slicedToArray(_ref, 1),
dirty = _ref2[0];
var categorylegenditemsymbol_changes = {};
if (dirty & /*item*/1) categorylegenditemsymbol_changes.item = /*item*/ctx[0];
categorylegenditemsymbol.$set(categorylegenditemsymbol_changes);
if ( /*stringLabel*/ctx[4]) {
if (if_block) {
if_block.p(ctx, dirty);
if (dirty & /*stringLabel*/16) {
transition_in(if_block, 1);
}
} else {
if_block = create_if_block$k(ctx);
if_block.c();
transition_in(if_block, 1);
if_block.m(div, null);
}
} else if (if_block) {
group_outros();
transition_out(if_block, 1, 1, function () {
if_block = null;
});
check_outros();
}
if (!current || dirty & /*item*/1 && div_tabindex_value !== (div_tabindex_value = /*item*/ctx[0].onClick ? 0 : -1)) {
attr(div, "tabindex", div_tabindex_value);
}
if (!current || dirty & /*item*/1) {
set_style(div, "--cursor-style", /*item*/ctx[0].onClick ? 'pointer' : 'default');
}
if (!current || dirty & /*refined*/8) {
toggle_class(div, "refined", /*refined*/ctx[3]);
}
},
i: function i(local) {
if (current) return;
transition_in(categorylegenditemsymbol.$$.fragment, local);
transition_in(if_block);
current = true;
},
o: function o(local) {
transition_out(categorylegenditemsymbol.$$.fragment, local);
transition_out(if_block);
current = false;
},
d: function d(detaching) {
if (detaching) detach(div);
destroy_component(categorylegenditemsymbol);
if (if_block) if_block.d();
mounted = false;
run_all(dispose);
}
};
}
function instance$E($$self, $$props, $$invalidate) {
var stringLabel;
var item = $$props.item;
var itemIndex = $$props.itemIndex;
var toggleSerie = $$props.toggleSerie;
var refined = $$props.refined;
var onKeyDown = function onKeyDown(event) {
if (event.key !== 'Enter' || !item.onClick) return;
toggleSerie(itemIndex);
item.onClick(itemIndex);
};
var click_handler = function click_handler() {
if (item.onClick) {
var _item$onClick, _item;
toggleSerie(itemIndex);
(_item$onClick = (_item = item).onClick) === null || _item$onClick === void 0 || _item$onClick.call(_item, itemIndex);
}
};
var mouseenter_handler = function mouseenter_handler() {
if (item.onHover) {
item.onHover(itemIndex, !refined);
}
};
var mouseleave_handler = function mouseleave_handler() {
if (item.onLeave) {
item.onLeave();
}
};
$$self.$$set = function ($$props) {
if ('item' in $$props) $$invalidate(0, item = $$props.item);
if ('itemIndex' in $$props) $$invalidate(1, itemIndex = $$props.itemIndex);
if ('toggleSerie' in $$props) $$invalidate(2, toggleSerie = $$props.toggleSerie);
if ('refined' in $$props) $$invalidate(3, refined = $$props.refined);
};
$$self.$$.update = function () {
if ($$self.$$.dirty & /*item, itemIndex*/3) {
var _item2, _item2$text;
$$invalidate(4, stringLabel = item.label && (typeof item.label === 'string' ? item.label : (_item2 = item) === null || _item2 === void 0 || (_item2 = _item2.label) === null || _item2 === void 0 || (_item2$text = _item2.text) === null || _item2$text === void 0 ? void 0 : _item2$text.call(_item2, itemIndex)));