Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support bin in barchart #134

Closed
wants to merge 317 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
317 commits
Select commit Hold shift + click to select a range
4213ade
Merge pull request #94 from togostanza/feature/piechart-event
penqe Feb 19, 2024
c27397e
Merge branch 'fix/lint-error' into feature/improve-selecting-rule-in-…
penqe Feb 19, 2024
46ef297
support click function
penqe Feb 19, 2024
ff0161c
Merge branch 'main' into feature/improve-selecting-rule-in-pagination…
penqe Feb 19, 2024
45f4d54
add click and dblclick events
maruk0chan Feb 19, 2024
aa42f5f
Merge remote-tracking branch 'origin/feature/add-event-util-function'…
maruk0chan Feb 19, 2024
e9d3c56
add event functions for tree and treemap
maruk0chan Feb 19, 2024
cce9fb3
support numbering forcedly in table rows
penqe Feb 19, 2024
0fbc23e
fix layout of pagination
penqe Feb 19, 2024
af82f58
support for changing id
penqe Feb 19, 2024
0157472
delete unnecessary codes
penqe Feb 19, 2024
c369631
support key conbination
penqe Feb 19, 2024
de4598d
temp
penqe Feb 20, 2024
6ce4617
temp
maruk0chan Feb 20, 2024
ecf4b1c
refactor drawing to stanza
maruk0chan Feb 20, 2024
b3bdd49
Merge pull request #93 from togostanza/feature/add-event-util-function
penqe Feb 20, 2024
16ca268
Disable text selection during shift-click table row selection
penqe Feb 22, 2024
4054236
dont render final column because it is not need
penqe Feb 23, 2024
06a24e6
support no data fallback
penqe Feb 23, 2024
1361fc2
rename a parameter
penqe Feb 26, 2024
235a227
lint
penqe Feb 26, 2024
0ad28d7
add -selected class to only one element in sunburst
maruk0chan Feb 27, 2024
7bb4561
able to add selected class in tree map
maruk0chan Feb 27, 2024
7db6641
remove console.log
maruk0chan Feb 27, 2024
0e9f6ab
document convert number to string code
maruk0chan Feb 27, 2024
0394a6c
refactor util parameter names
maruk0chan Feb 27, 2024
d7b9799
add highlight css style
maruk0chan Feb 27, 2024
ff88783
adjust treemap highlight style
maruk0chan Feb 27, 2024
ba47f45
avoid changing the id type outside the util fn
maruk0chan Feb 27, 2024
904e974
fix treemap not highlighting multi element
maruk0chan Feb 27, 2024
55a5d43
refactor util fn
maruk0chan Feb 27, 2024
68aaeef
use __togostanza_id__ as identifier
maruk0chan Feb 28, 2024
651da74
remove console.log
maruk0chan Feb 28, 2024
1711dd6
check vue input can add selected class
maruk0chan Feb 28, 2024
557e5ed
click checkbox can highlight other charts
maruk0chan Feb 29, 2024
23db7a1
piechart can check column tree
maruk0chan Mar 1, 2024
e28d57c
comment out code in sunburst handleEvent()
maruk0chan Mar 1, 2024
ddcea06
separate util fn into two
maruk0chan Mar 4, 2024
55163fb
swap to new util fn
maruk0chan Mar 4, 2024
3b9a6b6
refactor handleEvent
maruk0chan Mar 4, 2024
372a447
refactor if condition
maruk0chan Mar 4, 2024
bf6a4cb
refactor util functions
maruk0chan Mar 4, 2024
c49ca82
add comment in util fn
maruk0chan Mar 4, 2024
f6dce3b
remove console.log
maruk0chan Mar 4, 2024
6308b45
remove non d3 drawing logic and insert in component
maruk0chan Mar 4, 2024
db8270b
remove non-d3 logic from util fns
maruk0chan Mar 4, 2024
0f88ace
refactor util fns
maruk0chan Mar 4, 2024
a71283c
update typescript .d.ts
maruk0chan Mar 4, 2024
b771bbb
update the called function name
maruk0chan Mar 4, 2024
b121386
revert barchart function name changed
maruk0chan Mar 4, 2024
748f766
Merge branch 'refactor/util-functions' into feature/tree-type-graphs
maruk0chan Mar 4, 2024
4e3fda1
update function name
maruk0chan Mar 4, 2024
8a8e853
refactor code to expect number togostanza id
maruk0chan Mar 4, 2024
b497d47
change Number casting to plus mark
maruk0chan Mar 4, 2024
0afb2c8
Merge pull request #97 from togostanza/refactor/util-functions
penqe Mar 4, 2024
7751fc0
remove converting to string logic
maruk0chan Mar 4, 2024
0da05f1
persist selected treemap node style after level changed
maruk0chan Mar 5, 2024
efa97ab
add argument passed to event function
maruk0chan Mar 5, 2024
db5684e
add event to heatmap
YukikoNoda Feb 29, 2024
224c40c
remove hover & fix params
YukikoNoda Mar 5, 2024
6c61f48
update heatmap
YukikoNoda Mar 6, 2024
057bcda
npm install @types/topojson-client for namedmap
YukikoNoda Feb 29, 2024
d67269e
add event to namedmap
YukikoNoda Feb 29, 2024
1756e7c
fix params
YukikoNoda Mar 5, 2024
b3a83bf
update namedmap
YukikoNoda Mar 6, 2024
0b48ceb
Merge pull request #101 from togostanza/feature/heatmap-event
penqe Mar 6, 2024
66af35d
Merge pull request #100 from togostanza/feature/namedmap-event
penqe Mar 6, 2024
5b443f6
Merge pull request #99 from togostanza/feature/tree-type-graphs
penqe Mar 6, 2024
4fe5b2b
Merge branch 'feature/improve-barchart' into refactor/no-converting-t…
maruk0chan Mar 6, 2024
50cf4ab
Merge pull request #98 from togostanza/refactor/no-converting-to-string
maruk0chan Mar 6, 2024
b9709af
switch dataset to instance variable
maruk0chan Mar 6, 2024
c077215
Merge remote-tracking branch 'origin/dev' into feature/memorize-selec…
maruk0chan Mar 6, 2024
5a37103
delete comments
penqe Mar 6, 2024
e8345f9
remove console.log in sunburst
maruk0chan Mar 6, 2024
688382b
Merge branch 'dev' into feature/chord-force-layered-graphs
maruk0chan Mar 6, 2024
79819d5
Merge pull request #96 from togostanza/feature/improve-selecting-rule…
penqe Mar 6, 2024
b744300
Merge branch 'feature/correspond-to-events' into dev
penqe Mar 6, 2024
c9b986b
Merge branch 'main' into dev
penqe Mar 6, 2024
a2f4c8e
apply util function in chord force layered graphs
maruk0chan Mar 6, 2024
3b607d9
swap blue with red for highlight color
maruk0chan Mar 6, 2024
2e9b39c
Merge pull request #102 from togostanza/feature/memorize-select-treem…
maruk0chan Mar 6, 2024
716299c
change util event detail structure
maruk0chan Mar 11, 2024
fc44aac
change event detail structure
maruk0chan Mar 11, 2024
7e5d3b3
Merge pull request #103 from togostanza/feature/chord-force-layered-g…
maruk0chan Mar 11, 2024
6237202
Merge branch 'feature/check-matching-dataUrl' into fix/check-unshown-…
maruk0chan Mar 11, 2024
b93340b
sync selection between tree-like graph
maruk0chan Mar 11, 2024
a987195
refactor code (including removing console.log)
maruk0chan Mar 11, 2024
5a2cf44
not assign new Map() when no id selected
maruk0chan Mar 11, 2024
1172e45
disable selecting center
maruk0chan Mar 11, 2024
2ae6fd4
fix selection memory
maruk0chan Mar 11, 2024
3031ed3
avoid highlight treemap breadcrumb
maruk0chan Mar 11, 2024
74324b5
Merge pull request #105 from togostanza/fix/check-unshown-checkbox
maruk0chan Mar 12, 2024
a2a2d80
Merge pull request #106 from togostanza/fix/treemap-sunburst
maruk0chan Mar 12, 2024
47527ec
change highlight color to red
maruk0chan Mar 12, 2024
b026974
fix if there was no data-url
YukikoNoda Mar 12, 2024
e6cb5d4
Merge pull request #109 from togostanza/fix/display-nodataurl
penqe Mar 12, 2024
5505471
fix if data-url fetch error
YukikoNoda Mar 12, 2024
ec41a35
change highlight color to red
maruk0chan Mar 12, 2024
f31ee18
enable sunburst last child clickable
maruk0chan Mar 12, 2024
45039ad
enable treemap last child clickable
maruk0chan Mar 12, 2024
c7fc2c0
enable center click for real node
maruk0chan Mar 12, 2024
c86f9df
add and remove center circle event listener dynamically
maruk0chan Mar 12, 2024
f9b0f20
add local selectIds (temp)
maruk0chan Mar 12, 2024
29b05f4
fix no selectedIds memory
maruk0chan Mar 12, 2024
9680f8e
accept targetId in util fn
maruk0chan Mar 12, 2024
1b614c4
refactor
maruk0chan Mar 12, 2024
5ba15dc
fix sunburst center not sleeting
maruk0chan Mar 12, 2024
029676a
fix treemap not updating the local selectedIds after event
maruk0chan Mar 12, 2024
879a4a8
remove unused code
maruk0chan Mar 12, 2024
f359a70
fix piechart not highlighting
maruk0chan Mar 13, 2024
c95c015
update selectedIds when handle incoming event
maruk0chan Mar 13, 2024
11cd248
Merge pull request #110 from togostanza/feature/namedmap-nodataurl
penqe Mar 13, 2024
95c2236
fix chord-force-layered graph linkage
maruk0chan Mar 13, 2024
1178e09
rename fn name to emitSelectedEvent (Marco part only)
maruk0chan Mar 13, 2024
e85e06f
rename fn name to emitSelectedEvent (remaining part)
maruk0chan Mar 13, 2024
1da4da7
Merge branch 'dev' into fix/add-local-selectedIds-state
maruk0chan Mar 13, 2024
a46941c
fix selectedIds of heatmap, namedmap
YukikoNoda Mar 13, 2024
512f3c1
Merge pull request #113 from togostanza/fix/selectedIds-heatmap-namedmap
maruk0chan Mar 13, 2024
11c0498
api error msg for piechart
maruk0chan Mar 13, 2024
f0d18d4
Merge pull request #107 from togostanza/fix/change-highlight-color
maruk0chan Mar 13, 2024
2109db7
Merge pull request #111 from togostanza/fix/sunburst-treemap-last-chi…
maruk0chan Mar 13, 2024
603219b
Merge remote-tracking branch 'origin/dev' into fix/add-local-selected…
maruk0chan Mar 13, 2024
1d76f33
Merge pull request #112 from togostanza/fix/add-local-selectedIds-state
maruk0chan Mar 13, 2024
d82e297
add dataUrl check for stanza
maruk0chan Mar 13, 2024
aed446d
add dataUrl check for stanza
maruk0chan Mar 13, 2024
a9bab3c
add dataUrl check for chord related stanzas
maruk0chan Mar 14, 2024
98129ab
Merge branch 'feature/event-detail-dataUrl' into feature/api-error-msg
maruk0chan Mar 14, 2024
003c8a6
extends chord diagram from metastanza
maruk0chan Mar 14, 2024
7cdfd6e
add dataUrl check for force and layered graphs
maruk0chan Mar 14, 2024
52ffa53
add api error message for column tree
maruk0chan Mar 14, 2024
b184f60
add api error message for treemap and sunburst
maruk0chan Mar 14, 2024
c1ef2bd
Merge branch 'feature/api-error-msg' into feature/api-error-msg-for-n…
maruk0chan Mar 14, 2024
a30f856
Merge pull request #114 from togostanza/feature/event-detail-dataUrl
maruk0chan Mar 14, 2024
6996787
Merge remote-tracking branch 'origin/dev' into feature/api-error-msg
maruk0chan Mar 14, 2024
188e198
Merge branch 'feature/api-error-msg' into feature/api-error-msg-for-n…
maruk0chan Mar 14, 2024
b4876af
show data using asTree
maruk0chan Mar 15, 2024
322200b
temp
maruk0chan Mar 15, 2024
d1b35fb
ad togostanza id in treemap data
maruk0chan Mar 15, 2024
a1fc1b0
add apiError func
YukikoNoda Mar 15, 2024
94215fc
enable tree add selected class name
maruk0chan Mar 15, 2024
e2a543a
fix params name
YukikoNoda Mar 15, 2024
5c5275d
fix heatmap to typescript
YukikoNoda Mar 15, 2024
69ffc70
remove void
YukikoNoda Mar 15, 2024
46e01cf
fix optional
YukikoNoda Mar 15, 2024
4bdc7f1
add dataURL
YukikoNoda Mar 16, 2024
de72acc
add namedmap
YukikoNoda Mar 16, 2024
89eba30
Merge pull request #116 from togostanza/feature/api-error-msg
maruk0chan Mar 18, 2024
a7b46be
Merge pull request #117 from togostanza/feature/api-error-msg-for-non-d3
maruk0chan Mar 18, 2024
252a8fa
temp
maruk0chan Mar 18, 2024
0d6defe
Merge pull request #118 from togostanza/feature/api-error
maruk0chan Mar 18, 2024
3368053
remove hover highlight
maruk0chan Mar 18, 2024
edfce15
refactor util function
maruk0chan Mar 18, 2024
34fd06a
apply new function in piechart
maruk0chan Mar 18, 2024
ddd816f
add bar chart and histgram branches
penqe Mar 18, 2024
895ae11
enable chord force layered graphs standalone highlight
maruk0chan Mar 18, 2024
4689055
add data-url to heatmap and namedmap
YukikoNoda Mar 18, 2024
fc36d9e
fix standalone highlight to heatmap & namedmap
YukikoNoda Mar 19, 2024
2d38a1d
inprogress...
penqe Mar 19, 2024
22ebc95
add Promise to drawContent
YukikoNoda Mar 19, 2024
8cf899e
draw bin
penqe Mar 19, 2024
0c871f6
adjust size
penqe Mar 19, 2024
42574ab
change flag to toggle histogram or not
penqe Mar 19, 2024
e310b68
Merge pull request #119 from togostanza/feature/data-url-to-heatmap-a…
maruk0chan Mar 20, 2024
36ad217
enable treemap standalone highlight
maruk0chan Mar 20, 2024
d4f4314
enable sunburst standalone highlight
maruk0chan Mar 20, 2024
4937566
refactor treemap function and fix error
maruk0chan Mar 20, 2024
2c4044c
fix util function ts and remove apply
maruk0chan Mar 20, 2024
ee8341b
fix piechart apply logic
maruk0chan Mar 20, 2024
2f72692
remove apply in heatmap and namedmap
maruk0chan Mar 20, 2024
82cbb79
Merge branch 'fix/standalone-highlight' into feature/add-selection-in…
maruk0chan Mar 20, 2024
b39d1dc
fix tree select logic
maruk0chan Mar 20, 2024
9532b3e
fix treemap emit function args
maruk0chan Mar 20, 2024
01cb15d
fix sunburst center logic
maruk0chan Mar 20, 2024
1cddafe
Merge branch 'fix/standalone-highlight' into feature/add-selection-in…
maruk0chan Mar 20, 2024
831cb93
remove data-id attr and add selected class to label
maruk0chan Mar 20, 2024
eef1ddc
add selected style in tree
maruk0chan Mar 20, 2024
95e2d9f
update axis
penqe Mar 20, 2024
c1ef887
Merge branch 'feature/add-selection-into-tree' into feature/convert-t…
maruk0chan Mar 20, 2024
6474e43
finish converting to asTree and use tree.json as data-url
maruk0chan Mar 20, 2024
5673193
turn no children node to cursor-pointer
maruk0chan Mar 20, 2024
3cf706a
Merge branch 'feature/add-selection-into-tree' into feature/convert-t…
maruk0chan Mar 20, 2024
12ab9d6
refactor treemap data
maruk0chan Mar 20, 2024
31be7a4
change sunburst metadata
maruk0chan Mar 20, 2024
d7513ff
improve y axis
penqe Mar 20, 2024
e0424c9
use asTree in sunburst
maruk0chan Mar 20, 2024
4499f7d
show center circle at first (without label)
maruk0chan Mar 20, 2024
7ca74ca
remove console.log
maruk0chan Mar 20, 2024
ab7f491
switch column tree data to tree.json
maruk0chan Mar 20, 2024
d87052d
enable highlight other stanza from column tree
maruk0chan Mar 20, 2024
afe7160
inprogress...
penqe Mar 21, 2024
6ba90fa
enable error msg for piechart
maruk0chan Mar 21, 2024
aa4a1c3
fix ts type error
maruk0chan Mar 21, 2024
16f0295
return empty object to avoid error
maruk0chan Mar 21, 2024
e212f0f
add error msg for chord diagram
maruk0chan Mar 21, 2024
c607f52
add cursor pointer in piechart
maruk0chan Mar 21, 2024
0f5b1b2
specify legend option object type
maruk0chan Mar 21, 2024
9e1eab5
make all options keys optional
maruk0chan Mar 21, 2024
1cadfd0
fix type error
maruk0chan Mar 21, 2024
33c44e5
Merge branch 'feature/piechart-no-data-url-error-msg' into feature/gr…
maruk0chan Mar 21, 2024
af47afe
Merge pull request #124 from togostanza/feature/piechart-no-data-url-…
YukikoNoda Mar 21, 2024
e59e7b3
amend redraw tooltip logic
maruk0chan Mar 21, 2024
1dcfa76
fix chord diagram not showing tooltip
maruk0chan Mar 21, 2024
ac6ff92
add error msg for layered graph
maruk0chan Mar 21, 2024
5c69737
add error msg for force graph
maruk0chan Mar 21, 2024
ac4f9cf
add TODO comment for hasTooltip
maruk0chan Mar 21, 2024
b8c915f
add error msg for tree
maruk0chan Mar 21, 2024
cb9ec26
add error msg for treemap
maruk0chan Mar 21, 2024
7aa2d32
add error msg for column tree
maruk0chan Mar 21, 2024
4c32bfe
add error msg for sunburst
maruk0chan Mar 22, 2024
2c9a934
Merge pull request #120 from togostanza/fix/column-tree-no-item-highl…
maruk0chan Mar 22, 2024
d9294a6
Merge pull request #123 from togostanza/feature/convert-to-asTree
maruk0chan Mar 22, 2024
c4382c0
Merge pull request #121 from togostanza/fix/standalone-highlight
maruk0chan Mar 22, 2024
1129e42
Merge pull request #122 from togostanza/feature/add-selection-into-tree
maruk0chan Mar 25, 2024
fb27391
Merge pull request #125 from togostanza/feature/graphs-no-data-url-er…
maruk0chan Mar 25, 2024
a5cdbb0
Merge pull request #126 from togostanza/feature/trees-no-data-url-err…
maruk0chan Mar 25, 2024
0772539
auto reorganize import statements
maruk0chan Mar 25, 2024
7f10077
revert api error change
maruk0chan Mar 26, 2024
4452e2f
show root text info
maruk0chan Mar 26, 2024
4877b1a
dynamically add/remove click events
maruk0chan Mar 26, 2024
81e24c7
refactor to isNotZeroOpacity function
maruk0chan Mar 26, 2024
f01734e
fix lint error
maruk0chan Mar 26, 2024
6ccd115
Merge branch 'fix/sunburst-expansion-and-add-root-label' into fix/dis…
maruk0chan Mar 26, 2024
c2f1a94
add/remove click events after transitions
maruk0chan Mar 26, 2024
0ad4e10
hide highlight for node with zero fill-opacity
maruk0chan Mar 26, 2024
0766f35
show center highlight
maruk0chan Mar 26, 2024
4e06298
fix center circle not highlighting
maruk0chan Mar 27, 2024
97f7dc5
enable selecting highlight center from other stanzas
maruk0chan Mar 27, 2024
9a777d1
dynamically change center circle cursor
maruk0chan Mar 27, 2024
7c848c6
update arc selected class when clicking center
maruk0chan Mar 27, 2024
1f69edc
Merge pull request #128 from togostanza/fix/auto-reorganize-import
maruk0chan Mar 27, 2024
20d9724
Merge pull request #130 from togostanza/fix/revert-api-error-change
maruk0chan Mar 27, 2024
2565318
Merge pull request #131 from togostanza/fix/sunburst-expansion-and-ad…
maruk0chan Mar 27, 2024
32f54ff
Merge pull request #132 from togostanza/fix/disable-clicking-invisibl…
maruk0chan Mar 27, 2024
4ee945f
inprogress
penqe Apr 3, 2024
385ee71
fix y position
penqe Apr 4, 2024
9dd56f2
support fill color
penqe Apr 4, 2024
64073cf
support bin count
penqe Apr 4, 2024
2ea4fec
embed original values into bins
penqe Apr 4, 2024
db2df78
support event dispatch
penqe Apr 4, 2024
57f909b
tweak
penqe Apr 4, 2024
b768798
inprogress
penqe Apr 8, 2024
a326de2
support event sharing
penqe Apr 10, 2024
a83204f
Merge branch 'dev' into feature/support-bin-in-barchart
penqe Apr 11, 2024
97d9033
modify treemap
penqe Apr 11, 2024
8f94e4f
support asTree
penqe Apr 11, 2024
da73fef
tweak
penqe Apr 11, 2024
87daf55
import util and add logs
penqe May 9, 2024
7a165a7
support new select API in paginaiton table
penqe May 10, 2024
5c81641
support new API in barchart
penqe May 13, 2024
5314d74
support lint
penqe May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/AxisMixin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { select } from "d3-selection";
import { timeFormat } from "d3-time-format";
import { axisBottom, axisLeft, axisRight, axisTop } from "d3-axis";
import { format } from "d3-format";
import { scaleBand, scaleLinear, scaleLog, scaleTime } from "d3-scale";
import { select } from "d3-selection";
import {
utcDay,
utcHour,
utcMinute,
utcMonth,
utcSecond,
utcWeek,
utcMonth,
utcYear,
} from "d3-time";
import { axisBottom, axisLeft, axisRight, axisTop } from "d3-axis";
import { scaleLinear, scaleLog, scaleBand, scaleTime } from "d3-scale";
import { timeFormat } from "d3-time-format";
import { z } from "zod";

export const timeIntervalUnitsSchema = z
Expand Down
2 changes: 1 addition & 1 deletion lib/ColorGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { scaleOrdinal, scaleLinear } from "d3";
import { scaleLinear, scaleOrdinal } from "d3";

export default function getStanzaColors(stanza) {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Legend2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LitElement, html, css } from "lit";
import { createRef, ref } from "lit/directives/ref.js";
import { LitElement, css, html } from "lit";
import { classMap } from "lit/directives/class-map.js";
import { createRef, ref } from "lit/directives/ref.js";

export default class Legend2 extends LitElement {
/**
Expand Down
27 changes: 17 additions & 10 deletions lib/MetaStanza.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Stanza from "togostanza/stanza";
import { appendCustomCss } from "togostanza-utils";
import { getMarginsFromCSSString, MarginsI } from "./utils";
import { Data } from "togostanza-utils/data";
import Stanza from "togostanza/stanza";
import { getMarginsFromCSSString, MarginsI } from "./utils";

export default abstract class extends Stanza {
_data: any;
__data: Data;
_main: HTMLElement;
abstract renderNext(): Promise<void>;
_apiError = false;
_error: Error;

get MARGIN(): MarginsI {
return getMarginsFromCSSString(this.css("--togostanza-canvas-padding"));
Expand All @@ -24,13 +26,18 @@ export default abstract class extends Stanza {

// To maintain compatibility, we assign values to __data,
// but in the future we would like to make _data the return value of Data.load itself.
this.__data = await Data.load(this.params["data-url"], {
type: this.params["data-type"],
mainElement: this._main,
});

this._data = this.__data.data;

await this.renderNext();
try {
this.__data = await Data.load(this.params["data-url"], {
type: this.params["data-type"],
mainElement: this._main,
});
this._data = this.__data.data;
this._apiError = false;
} catch (error) {
this._apiError = true;
this._error = error;
} finally {
await this.renderNext();
}
}
}
4 changes: 2 additions & 2 deletions lib/ToolTip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LitElement, html, css } from "lit";
import { ref, createRef } from "lit/directives/ref.js";
import { LitElement, css, html } from "lit";
import { createRef, ref } from "lit/directives/ref.js";

function isInNodeList(nodeList, node) {
for (const nodeInList of nodeList.values()) {
Expand Down
145 changes: 145 additions & 0 deletions lib/apiError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import type { BaseType } from "d3";
import Legend from "./Legend2.js";
import ToolTip from "./ToolTip.js";

/**
* Options for handling API errors in the visualization.
* @interface
* @property {StanzaData} stanzaData - The data of the current stanza.
* @property {() => void} drawContent - A function to draw the content of the stanza.
* @property {boolean} [hasLegend] - Indicates whether the legend should be displayed.
* @property {boolean} [hasTooltip] - Indicates whether tooltips should be displayed.
* @property {LegendOptions} [legendOptions] - Configuration options for the legend.
*/
interface HandleApiErrorOptions {
stanzaData: StanzaData;
drawContent: () => void;
hasLegend?: boolean;
hasTooltip?: boolean;
legendOptions?: LegendOptions;
}

/**
* Represents the data needed to handle an API error.
*/
interface StanzaData {
_main: HTMLElement;
_apiError: boolean;
root: ShadowRoot;
}

/**
* Represents an item in the legend.
*/
export interface LegendItem {
id: string | number;
color: string;
value: string | number;
toggled?: boolean;
}

/**
* Represents the configuration for the legend.
*/
interface LegendConfiguration {
items: LegendItem[];
title: string;
options: {
fadeoutNodes?: NodeList | BaseType[];
shape?: string;
fadeProp?: string;
position?: string;
showLeaders?: boolean;
};
}

/**
* Represents the options for displaying the legend.
*/
interface LegendOptions {
isLegendVisible: boolean;
legendConfiguration: LegendConfiguration;
}

/**
* Handles API errors by displaying an error message or rendering the content.
* Also manages legend and tooltip based on the configuration.
*/
export async function handleApiError(options: HandleApiErrorOptions) {
const { stanzaData, drawContent, hasLegend, hasTooltip, legendOptions } =
options;
const { _main: main, _apiError: apiError, root } = stanzaData;
const { isLegendVisible, legendConfiguration } = legendOptions ?? {};

handleErrorMessage(apiError, main);
if (!apiError) {
await drawContent();
}
if (hasLegend) {
manageLegend(isLegendVisible, legendConfiguration, root, apiError);
}
/* TODO hasTooltip should be determined by the data fetched from the data-url.
(e.g. const showToolTips = dataset.some((item) => item.description);)
The function now can only accept hardcode boolean value */
if (hasTooltip) {
manageTooltip(main);
}
}

/**
* Displays or removes an error message based on the API error status.
* @param apiError - Indicates if there is an API error.
* @param main - The main HTML element to display the error message.
*/
function handleErrorMessage(apiError: boolean, main: HTMLElement) {
const errorMessageEl = main.querySelector(".metastanza-error-message-div");

if (apiError) {
if (!errorMessageEl) {
const errorMessageDiv = document.createElement("div");
errorMessageDiv.className = "metastanza-error-message-div";
errorMessageDiv.textContent = "Please fill in the exact data-url";
main.appendChild(errorMessageDiv);
}
} else {
errorMessageEl?.remove();
}
}

/**
* Manages the display of the legend based on the given parameters.
* @param isShow - Determines whether the legend should be displayed.
* @param config - The configuration for the legend.
* @param root - The root HTML element where the legend will be displayed.
* @param apiError - Indicates if there is an API error.
*/
function manageLegend(
isShow: boolean,
config: LegendConfiguration,
root: ShadowRoot,
apiError: boolean
) {
const legendElement = root.querySelector("togostanza--legend2");
if (!isShow || apiError) {
legendElement?.remove();
} else if (!legendElement) {
const legend = new Legend();
root.append(legend);
legend.setup(config);
}
}

/**
* Manages the tooltip by removing any existing tooltip and creating a new one if necessary.
* @param main - The main HTML element where the tooltip will be displayed.
*/
function manageTooltip(main: HTMLElement) {
const tooltipElement = main.querySelector("togostanza--tooltip");
if (!tooltipElement) {
const tooltip = new ToolTip();
main.append(tooltip);
tooltip.setup(main.querySelectorAll("[data-tooltip]"));
} else {
tooltipElement.remove();
}
}
24 changes: 24 additions & 0 deletions lib/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ interface MarginsI {
}

export function getMarginsFromCSSString(cssString: string): MarginsI;

export function toggleSelectIds({ targetId, selectedIds }): void;

export function emitSelectedEvent({
rootElement = undefined,
targetId,
selectedIds,
dataUrl,
}): void;

export function updateSelectedElementClassNameForD3({
drawing,
selectedIds,
targetElementSelector,
selectedElementClassName,
idPath,
}): void;

export function selectElement({
stanza,
selectedIds,
targetElementSelector,
idPrefix,
}): void;
51 changes: 51 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from "axios";
import camelCase from "lodash.camelcase";
import get from "lodash.get";

/** Cached axios */
export class cachedAxios {
/**
Expand Down Expand Up @@ -143,3 +145,52 @@ export function checkIfHexColor(text) {
const regex = /^#(?:[0-9a-f]{3}){1,2}$/i;
return regex.test(text);
}

export function toggleSelectIds({ selectedIds, targetId }) {
!selectedIds.includes(targetId)
? selectedIds.push(targetId)
: selectedIds.splice(selectedIds.indexOf(targetId), 1);
}
export function emitSelectedEvent({
rootElement = undefined,
selectedIds,
targetId,
dataUrl,
}) {
rootElement.dispatchEvent(
new CustomEvent("changeSelectedNodes", {
detail: { targetId, selectedIds, dataUrl },
})
);
}

export function updateSelectedElementClassNameForD3({
drawing,
selectedIds,
targetElementSelector,
selectedElementClassName,
idPath,
}) {
drawing
.selectAll(targetElementSelector)
.classed(selectedElementClassName, (d) => {
const targetId = get(d, idPath);
return selectedIds.indexOf(targetId) !== -1;
});
}

// TODO update utils.d.ts and JSDoc

export function displayApiError(element, error) {
const htmlString = `
<div class="metastanza-error-message-div">
<p class="metastanza-error-message">
<span>MetaStanza API error</span>
<br>
<span>${error.name}: ${error.message}</span>
</p>
</div>
`;

element.insertAdjacentHTML("beforeend", htmlString);
}
39 changes: 39 additions & 0 deletions package-lock.json

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

Loading
Loading