Skip to content

Commit

Permalink
Working on data display line num policies
Browse files Browse the repository at this point in the history
  • Loading branch information
stricklandrbls committed Sep 28, 2023
1 parent 4bd33db commit c13707a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

import { SimpleWritable } from '../../../stores/localStore'
import {
dataDisplayLineCount,
type BytesPerRow,
type RadixValues,
data_dislay_line_amount,
} from '../../../stores/configuration'
import {
radixBytePad,
viewport_offset_to_line_num,
} from '../../../utilities/display'

import { get } from 'svelte/store'

export const BYTE_ACTION_DIV_OFFSET: number = 24
Expand All @@ -38,7 +39,7 @@ export type EditAction =

export type ByteValue = {
offset: number
text: string | undefined
text: string
value: number
}

Expand Down Expand Up @@ -112,17 +113,15 @@ export class ViewportDataStore_t extends SimpleWritable<ViewportData_t> {
public upperFetchBoundary(bytesPerRow: BytesPerRow): number {
const store = this.storeData()
const boundary =
store.fileOffset +
store.length -
get(data_dislay_line_amount) * bytesPerRow
store.fileOffset + store.length - get(dataDisplayLineCount) * bytesPerRow

return boundary
}

public lineTopMax(bytesPerRow: BytesPerRow): number {
const vpMaxOffset = Math.max(
0,
this.storeData().length - get(data_dislay_line_amount) * bytesPerRow
this.storeData().length - get(dataDisplayLineCount) * bytesPerRow
)
const vpLineTopMax = viewport_offset_to_line_num(
vpMaxOffset + this.storeData().fileOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ limitations under the License.
editorActionsAllowed,
dataFeedLineTop,
seekOffsetInput,
tooltipsEnabled,
viewport,
dataDisplayLineCount
} from '../../../stores'
import {
EditByteModes,
data_dislay_line_amount,
type RadixValues,
EditActionRestrictions,
VIEWPORT_SCROLL_INCREMENT,
Expand Down Expand Up @@ -94,7 +92,7 @@ limitations under the License.
if (fetchBound > $fileMetrics.computedSize)
return (
($fileMetrics.computedSize / $bytesPerRow) * $bytesPerRow -
$data_dislay_line_amount * $bytesPerRow
$dataDisplayLineCount * $bytesPerRow
)
return fetchBound
Expand Down Expand Up @@ -128,15 +126,15 @@ limitations under the License.
}
const INCREMENT_SEGMENT = () => {
$seekOffsetInput = line_num_to_file_offset(
$dataFeedLineTop + $data_dislay_line_amount,
$dataFeedLineTop + $dataDisplayLineCount,
viewportData.fileOffset,
$bytesPerRow
).toString(addressRadix)
eventDispatcher('seek')
}
const DECREMENT_SEGMENT = () => {
$seekOffsetInput = line_num_to_file_offset(
$dataFeedLineTop - $data_dislay_line_amount,
$dataFeedLineTop - $dataDisplayLineCount,
viewportData.fileOffset,
$bytesPerRow
).toString(addressRadix)
Expand Down Expand Up @@ -181,7 +179,7 @@ limitations under the License.
INCREMENT = 1,
}
let height = `calc(${$data_dislay_line_amount} * 20)px`
let height = `calc(${$dataDisplayLineCount} * 20)px`
let viewportLines: Array<ViewportLineData> = []
let viewportDataContainer: HTMLDivElement
let selectedByteElement: HTMLDivElement
Expand All @@ -201,9 +199,9 @@ limitations under the License.
$: {
totalLinesPerFilesize = Math.ceil($fileMetrics.computedSize / $bytesPerRow)
totalLinesPerViewport = Math.ceil(viewportData.data.length / $bytesPerRow)
lineTopMaxFile = Math.max(totalLinesPerFilesize - $data_dislay_line_amount, 0)
lineTopMaxFile = Math.max(totalLinesPerFilesize - $dataDisplayLineCount, 0)
lineTopMaxViewport = Math.max(
totalLinesPerViewport - $data_dislay_line_amount,
totalLinesPerViewport - $dataDisplayLineCount,
0
)
Expand Down Expand Up @@ -253,14 +251,14 @@ limitations under the License.
startIndex: number,
dataRadix: RadixValues,
addressRadix: RadixValues,
endIndex: number = startIndex + ($data_dislay_line_amount - 1)
): Array<ViewportLineData> {
let ret = []
endIndex: number = startIndex + ($dataDisplayLineCount - 1)
): ViewportLineData[] {
let ret:ViewportLineData[] = []
for (let i = startIndex; i <= endIndex; i++) {
const viewportLineOffset = i * $bytesPerRow
const fileOffset = viewportLineOffset + viewportData.fileOffset
let bytes: Array<ByteValue> = []
let bytes: ByteValue[] = []
const highlight = i % 2 === 0
for (let bytePos = 0; bytePos < $bytesPerRow; bytePos++) {
Expand Down Expand Up @@ -444,7 +442,7 @@ limitations under the License.
($fileMetrics.computedSize * (percentageTraversed / 100.0)) /
$bytesPerRow
) * $bytesPerRow
const firstPageThreshold = $bytesPerRow * $data_dislay_line_amount
const firstPageThreshold = $bytesPerRow * $dataDisplayLineCount
const lastPageThreshold = $fileMetrics.computedSize - firstPageThreshold
if (offset <= firstPageThreshold) {
// scroll to the top because we are somewhere in the first page
Expand Down Expand Up @@ -570,7 +568,7 @@ limitations under the License.
selectionActive={$selectionDataStore.active}
currentLine={$dataFeedLineTop}
fileOffset={viewportData.fileOffset}
maxDisplayLines={$data_dislay_line_amount}
maxDisplayLines={$dataDisplayLineCount}
bind:percentageTraversed
on:indicatorClicked={handleClickedIndicator}
/>
Expand All @@ -590,7 +588,7 @@ limitations under the License.
fn={INCREMENT_SEGMENT}
disabledBy={disableIncrement}
width="30pt"
description="Increment offset by {$data_dislay_line_amount *
description="Increment offset by {$dataDisplayLineCount *
$bytesPerRow} bytes"
tooltipAlwaysEnabled={true}
>
Expand Down Expand Up @@ -624,7 +622,7 @@ limitations under the License.
fn={DECREMENT_SEGMENT}
disabledBy={disableDecrement}
width="30pt"
description="Decrement offset by {$data_dislay_line_amount *
description="Decrement offset by {$dataDisplayLineCount *
$bytesPerRow} bytes"
tooltipAlwaysEnabled={true}
>
Expand All @@ -646,16 +644,16 @@ limitations under the License.
<span class="separator" />
<Button
fn={() => {
update_num_lines_displayed($data_dislay_line_amount+1)
update_num_lines_displayed($dataDisplayLineCount+1)
viewportLines = generate_line_data(
$dataFeedLineTop,
dataRadix,
addressRadix
)
}
}
disabledBy={ ($data_dislay_line_amount*$bytesPerRow >= 512) }
description={"Increment display lines (" + ($data_dislay_line_amount+1) + ")"}
disabledBy={ ($dataDisplayLineCount*$bytesPerRow >= 512) }
description={"Increment display lines (" + ($dataDisplayLineCount+1) + ")"}
tooltipAlwaysEnabled={true}
width="30pt"
>
Expand All @@ -665,16 +663,16 @@ limitations under the License.
</Button>
<Button
fn={() => {
update_num_lines_displayed($data_dislay_line_amount-1)
update_num_lines_displayed($dataDisplayLineCount-1)
viewportLines = generate_line_data(
$dataFeedLineTop,
dataRadix,
addressRadix
)
}
}
disabledBy={$data_dislay_line_amount === 1}
description={"Decrement display lines (" + ($data_dislay_line_amount-1) + ")"}
disabledBy={$dataDisplayLineCount === 1}
description={"Decrement display lines (" + ($dataDisplayLineCount-1) + ")"}
tooltipAlwaysEnabled={true}
width="30pt"
>
Expand Down
10 changes: 6 additions & 4 deletions src/svelte/src/stores/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { get, writable } from 'svelte/store'
import { dataDisplayLineCount } from '.'

export type Radixes = 'Hexadecimal' | 'Decimal' | 'Octal' | 'Binary'

Expand Down Expand Up @@ -114,9 +114,11 @@ export const VIEWPORT_CAPACITY_MAX = 16 * 64 // 1024, Ωedit maximum viewport si
// Offset shift amount on viewport data fetch
export const VIEWPORT_SCROLL_INCREMENT = VIEWPORT_CAPACITY_MAX / 2

// Number of bytes to display in the viewport
export const data_dislay_line_amount = writable(20)
export function update_num_lines_displayed(line_num: number) {
data_dislay_line_amount.set(line_num)
dataDisplayLineCount.set(line_num)
}
export function can_update_num_lines_displayed(line_num: number): boolean {
return false
}
export const DATA_PROFILE_MAX_LENGTH = 10_000_000
export { dataDisplayLineCount }
18 changes: 16 additions & 2 deletions src/svelte/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
type RadixValues,
type BytesPerRow,
EditActionRestrictions,
VIEWPORT_SCROLL_INCREMENT,
} from './configuration'

export class SelectionData_t {
Expand Down Expand Up @@ -147,6 +148,19 @@ export const sizeHumanReadable = writable(false)
// tracks the start and end offsets of the current selection
export const selectionDataStore = new SelectionData()

// Number of bytes to display in the viewport
export const dataDisplayLineCount = writable(20)

export const MAX_DATA_DISPLAY_LINE_COUNT = derived(
[dataDisplayLineCount, bytesPerRow],
([$dataDisplayLineCount, $bytesPerRow]) => {
if ($dataDisplayLineCount * $bytesPerRow >= VIEWPORT_SCROLL_INCREMENT)
return false
if ($dataDisplayLineCount === 1) return false
return true
}
)

// Can the user's selection derive both edit modes?
export const regularSizedFile = derived(fileMetrics, ($fileMetrics) => {
return $fileMetrics.computedSize >= 2
Expand Down Expand Up @@ -287,8 +301,8 @@ export const editedByteIsOriginalByte = derived(
[editorSelection, selectedByte, focusedViewportId],
([$editorSelection, $selectedByte, $focusedViewportId]) => {
return $focusedViewportId === 'logical'
? $editorSelection === $selectedByte.text
: $editorSelection.toLowerCase() === $selectedByte.text.toLowerCase()
? $editorSelection === $selectedByte.text!
: $editorSelection.toLowerCase() === $selectedByte.text!.toLowerCase()
}
)

Expand Down

0 comments on commit c13707a

Please sign in to comment.