@matdata/yasgui-chart-plugin 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,6 +88,11 @@
88
88
  background: var(--chart-control-hover);
89
89
  }
90
90
 
91
+ .chart-toolbar-button[aria-pressed='true'] {
92
+ border-color: var(--yasgui-brand, #0563bb);
93
+ color: var(--yasgui-brand, #0563bb);
94
+ }
95
+
91
96
  .chart-toolbar-spacer {
92
97
  flex: 1;
93
98
  }
@@ -196,24 +201,20 @@
196
201
  gap: 8px;
197
202
  }
198
203
 
204
+ /* The .yasr_toolbarSelect field already draws the box: the summary sits in it
205
+ like a <select> does, without a border of its own */
199
206
  .yasr_toolbarSelect .chart-values-summary {
200
207
  box-sizing: border-box;
201
- height: 30px;
202
- padding: 0 10px;
208
+ height: 28px;
209
+ padding: 0 8px 0 0;
203
210
  gap: 2px;
204
- border: 1px solid var(--yasgui-line-strong, var(--chart-border));
205
- border-radius: var(--yasgui-radius-button, 8px);
206
- background: var(--yasgui-surface-raised, var(--chart-background));
211
+ border: none;
212
+ background: transparent;
207
213
  color: var(--yasgui-ink, var(--chart-text));
208
214
  font: inherit;
209
- font-weight: 500;
210
215
  cursor: pointer;
211
216
  }
212
217
 
213
- .yasr_toolbarSelect .chart-values-summary:hover {
214
- background: var(--yasgui-surface-sunken, var(--chart-control-hover));
215
- }
216
-
217
218
  .yasr_toolbarSelect .chart-values-summary:focus-visible,
218
219
  .chart-view-settings-item:focus-visible {
219
220
  outline: 2px solid var(--yasgui-focus, #044a8c);
@@ -47203,6 +47203,8 @@ var ICON_PATHS = {
47203
47203
  "chevrons-left": '<path d="m11 17-5-5 5-5"/><path d="m18 17-5-5 5-5"/>',
47204
47204
  x: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
47205
47205
  download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" x2="12" y1="15" y2="3"/>',
47206
+ square: '<rect width="18" height="18" x="3" y="3" rx="2"/>',
47207
+ "square-check": '<rect width="18" height="18" x="3" y="3" rx="2"/><path d="m9 12 2 2 4-4"/>',
47206
47208
  "rotate-ccw": '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/>'
47207
47209
  };
47208
47210
  function iconSvg(name, size = 16, strokeWidth = 1.75) {
@@ -47242,12 +47244,19 @@ function sanitizeSettings(raw) {
47242
47244
  if (typeof r.series === "string") settings.series = r.series;
47243
47245
  if (Array.isArray(r.columns))
47244
47246
  settings.columns = r.columns.filter((v) => typeof v === "string");
47247
+ if (typeof r.shortenIris === "boolean") settings.shortenIris = r.shortenIris;
47245
47248
  return settings;
47246
47249
  }
47250
+ function isCustomised(saved) {
47251
+ return Object.keys(saved).some((key) => key !== "columns" && key !== "shortenIris");
47252
+ }
47253
+ function displayOptions(saved) {
47254
+ return saved.shortenIris === void 0 ? {} : { shortenIris: saved.shortenIris };
47255
+ }
47247
47256
  function settingsForColumns(saved, vars) {
47248
47257
  if (!saved.columns) return saved;
47249
47258
  const same = saved.columns.length === vars.length && saved.columns.every((v, i) => v === vars[i]);
47250
- return same ? saved : {};
47259
+ return same ? saved : displayOptions(saved);
47251
47260
  }
47252
47261
  function categoryCandidates(columns) {
47253
47262
  return columns.filter((c) => !c.isLabel && c.bound > 0);
@@ -47483,6 +47492,14 @@ function renderToolbar(state, callbacks) {
47483
47492
  const spacer = document.createElement("div");
47484
47493
  spacer.className = "chart-toolbar-spacer";
47485
47494
  toolbar.appendChild(spacer);
47495
+ const shorten = button(
47496
+ "chart-shorten-iris",
47497
+ "Prefixes",
47498
+ "Show IRIs as prefixed names",
47499
+ () => callbacks.onShortenIris(!state.shortenIris)
47500
+ );
47501
+ shorten.setAttribute("aria-pressed", String(state.shortenIris));
47502
+ toolbar.appendChild(shorten);
47486
47503
  toolbar.appendChild(
47487
47504
  button(
47488
47505
  "chart-export-png",
@@ -47551,6 +47568,16 @@ function renderViewSettings(state, callbacks) {
47551
47568
  );
47552
47569
  reset.disabled = !state.customised;
47553
47570
  menu.appendChild(reset);
47571
+ const shorten = menuItem(
47572
+ "chart-shorten-iris",
47573
+ state.shortenIris ? "square-check" : "square",
47574
+ "Shorten IRIs with prefixes",
47575
+ "Show IRIs as prefixed names, such as ex:Germany",
47576
+ run(() => callbacks.onShortenIris(!state.shortenIris))
47577
+ );
47578
+ shorten.setAttribute("role", "menuitemcheckbox");
47579
+ shorten.setAttribute("aria-checked", String(state.shortenIris));
47580
+ menu.appendChild(shorten);
47554
47581
  const separator = document.createElement("div");
47555
47582
  separator.className = "chart-view-settings-separator";
47556
47583
  separator.setAttribute("role", "separator");
@@ -50857,6 +50884,18 @@ var DescribeModal = class {
50857
50884
  };
50858
50885
 
50859
50886
  // src/ChartPlugin.ts
50887
+ var COMMON_PREFIXES = {
50888
+ rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
50889
+ rdfs: "http://www.w3.org/2000/01/rdf-schema#",
50890
+ owl: "http://www.w3.org/2002/07/owl#",
50891
+ xsd: "http://www.w3.org/2001/XMLSchema#",
50892
+ foaf: "http://xmlns.com/foaf/0.1/",
50893
+ dc: "http://purl.org/dc/elements/1.1/",
50894
+ dcterms: "http://purl.org/dc/terms/",
50895
+ skos: "http://www.w3.org/2004/02/skos/core#",
50896
+ schema: "http://schema.org/",
50897
+ wd: "http://www.wikidata.org/entity/"
50898
+ };
50860
50899
  use([
50861
50900
  install2,
50862
50901
  install,
@@ -50976,6 +51015,14 @@ var ChartPlugin = class {
50976
51015
  }
50977
51016
  return prefixes;
50978
51017
  }
51018
+ /**
51019
+ * Prefixes used to show IRIs in the chart: well-known ones, then those of
51020
+ * Yasr and the query. None when the user turned shortening off.
51021
+ */
51022
+ getLabelPrefixes() {
51023
+ if (this.saved.shortenIris === false) return {};
51024
+ return { ...COMMON_PREFIXES, ...this.getPrefixes() };
51025
+ }
50979
51026
  /** Build the toolbar and chart for the current results and settings */
50980
51027
  render() {
50981
51028
  var _a2;
@@ -50986,17 +51033,19 @@ var ChartPlugin = class {
50986
51033
  const allRows = this.results.results.bindings;
50987
51034
  const rows = allRows.length > maxRows ? allRows.slice(0, maxRows) : allRows;
50988
51035
  this.resolved = resolveSettings(this.columns, this.saved, rows.length);
50989
- this.data = buildChartData(rows, this.columns, this.resolved, this.getPrefixes());
51036
+ this.data = buildChartData(rows, this.columns, this.resolved, this.getLabelPrefixes());
50990
51037
  const wrapper = document.createElement("div");
50991
51038
  wrapper.className = "yasgui-chart-plugin";
50992
51039
  const toolbarState = {
50993
51040
  columns: this.columns,
50994
51041
  resolved: this.resolved,
50995
- customised: Object.keys(this.saved).length > 0
51042
+ customised: isCustomised(this.saved),
51043
+ shortenIris: this.saved.shortenIris !== false
50996
51044
  };
50997
51045
  const toolbarCallbacks = {
50998
- onChange: (settings) => this.updateSettings(settings),
50999
- onReset: () => this.updateSettings({}),
51046
+ onChange: (settings) => this.updateSettings({ ...displayOptions(this.saved), ...settings }),
51047
+ onReset: () => this.updateSettings(displayOptions(this.saved)),
51048
+ onShortenIris: (shortenIris) => this.updateSettings({ ...this.saved, shortenIris }),
51000
51049
  onExport: (format2) => this.exportImage(format2)
51001
51050
  };
51002
51051
  const slot = getHostToolbar(this.yasr);
@@ -51081,8 +51130,7 @@ var ChartPlugin = class {
51081
51130
  }
51082
51131
  updateSettings(settings) {
51083
51132
  this.saved = sanitizeSettings(settings);
51084
- if (Object.keys(this.saved).length > 0 && this.results)
51085
- this.saved.columns = [...this.results.head.vars];
51133
+ if (isCustomised(this.saved) && this.results) this.saved.columns = [...this.results.head.vars];
51086
51134
  if (typeof this.yasr.storePluginConfig === "function") {
51087
51135
  try {
51088
51136
  this.yasr.storePluginConfig(this.getPluginName(), this.saved);